1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/*
* TransFig: Facility for Translating Fig code
* Copyright (c) 1991 by Micah Beck
* Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul
* Parts Copyright (c) 1989-2014 by Brian V. Smith
*
* Any party obtaining a copy of these files is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and
* documentation files (the "Software"), including without limitation the
* rights to use, copy, modify, merge, publish and/or distribute copies of
* the Software, and to permit persons who receive copies from any such
* party to do so, with the only requirement being that this copyright
* notice remain intact.
*
* creationdate.c - created 2016-06-28 by Thomas Loimer
*
* * 2016-07-22 remove HAVE_LIMITS_H
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
//#include <signal.h>
#include <string.h>
#ifdef HAVE_STRERROR
#include <errno.h>
#endif
#include <time.h>
#include <limits.h>
#include "bool.h"
#include "creationdate.h"
int
creation_date(char *buf)
{
time_t now;
#ifdef HAVE_STRERROR
char *source_date_epoch;
unsigned long long epoch;
char *endptr;
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf(stderr,
"Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
strerror(errno));
} else if (endptr == source_date_epoch) {
fprintf(stderr,
"Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
endptr);
} else if (*endptr != '\0') {
fprintf(stderr,
"Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
endptr);
} else if (epoch > ULONG_MAX) {
fprintf(stderr,
"Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu \n",
ULONG_MAX, epoch);
} else {
/* no errors, epoch is valid */
now = epoch;
strftime(buf, CREATION_TIME_LEN, "%F %H:%M:%S", gmtime(&now));
return true;
}
}
#endif
/* fall trough on errors or !source_date_epoch */
time(&now);
if (strftime(buf, CREATION_TIME_LEN, "%F %H:%M:%S", localtime(&now)))
return true;
else
return false;
}
|