allow to override man-page date

in order to allow for reproducible builds.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
pull/193/head
Bernhard M. Wiedemann 8 years ago
parent 4d322880f4
commit cb445d3b32
  1. 28
      mxmldoc.c

@ -23,6 +23,7 @@
#include "zipc.h" #include "zipc.h"
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <limits.h>
#ifndef WIN32 #ifndef WIN32
# include <dirent.h> # include <dirent.h>
# include <unistd.h> # include <unistd.h>
@ -5086,6 +5087,7 @@ write_man(const char *man_name, /* I - Name of manpage */
char prefix; /* Prefix character */ char prefix; /* Prefix character */
time_t curtime; /* Current time */ time_t curtime; /* Current time */
struct tm *curdate; /* Current date */ struct tm *curdate; /* Current date */
char *source_date_epoch; /* ENV string */
char buffer[1024]; /* String buffer */ char buffer[1024]; /* String buffer */
static const char * const scopes[] = /* Scope strings */ static const char * const scopes[] = /* Scope strings */
{ {
@ -5099,7 +5101,33 @@ write_man(const char *man_name, /* I - Name of manpage */
* Standard man page... * Standard man page...
*/ */
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
char *endptr;
unsigned long long 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));
exit(EXIT_FAILURE);
}
if (endptr == source_date_epoch) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (*endptr != '\0') {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
exit(EXIT_FAILURE);
}
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);
exit(EXIT_FAILURE);
}
curtime = epoch;
} else {
curtime = time(NULL); curtime = time(NULL);
}
curdate = localtime(&curtime); curdate = localtime(&curtime);
strftime(buffer, sizeof(buffer), "%x", curdate); strftime(buffer, sizeof(buffer), "%x", curdate);

Loading…
Cancel
Save