From f14daac6b6677753c7a1fc54ea2dfff39997e91b Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Wed, 4 May 2016 12:10:04 +0000 Subject: dvipsk: support SOURCE_DATE_EPOCH for %%CreationDate git-svn-id: svn://tug.org/texlive/trunk@40885 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipsk/ChangeLog | 4 ++++ Build/source/texk/dvipsk/output.c | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'Build/source') diff --git a/Build/source/texk/dvipsk/ChangeLog b/Build/source/texk/dvipsk/ChangeLog index 3d06bf0435c..356a0010db9 100644 --- a/Build/source/texk/dvipsk/ChangeLog +++ b/Build/source/texk/dvipsk/ChangeLog @@ -1,3 +1,7 @@ +2016-05-04 Akira Kakuto + + * output.c: Support SOURCE_DATE_EPOCH for %%CreationDate. + 2016-03-24 Akira Kakuto * writet1.c: Fix one-byte buffer overflow bug reported by Hanno Boeck: diff --git a/Build/source/texk/dvipsk/output.c b/Build/source/texk/dvipsk/output.c index 0fc3d7ad691..ff5931c3b18 100644 --- a/Build/source/texk/dvipsk/output.c +++ b/Build/source/texk/dvipsk/output.c @@ -85,7 +85,32 @@ static struct papsiz defpapsiz = { #endif #include /* asctime() and localtime(), at least on BSD Unix */ static time_t jobtime; + +#if defined(_MSC_VER) +#define strtoll _strtoi64 #endif + +#define INVALID_EPOCH_VALUE 0x7fffffffffffffffULL + +static time_t +get_unique_time_if_given(void) +{ + const char *source_date_epoch; + int64_t epoch; + char *endptr; + time_t ret = INVALID_EPOCH_VALUE; + + source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) { + errno = 0; + epoch = strtoll(source_date_epoch, &endptr, 10); + if (!(epoch < 0 || *endptr != '\0' || errno != 0)) + ret = (time_t) epoch; + } + return ret; +} +#endif /* CREATIONDATE */ + /* * This routine copies a file down the pipe. Search path uses the * header path. @@ -1388,9 +1413,15 @@ initprinter(sectiontype *sect) if (*iname) fprintf(bitfile, "%%%%Title: %s\n", iname); #ifdef CREATIONDATE - jobtime=time(0); - fprintf(bitfile, "%%%%CreationDate: %s", - asctime(localtime(&jobtime))); + jobtime = get_unique_time_if_given(); + if (jobtime == INVALID_EPOCH_VALUE) { + jobtime = time(0); + fprintf(bitfile, "%%%%CreationDate: %s", + asctime(localtime(&jobtime))); + } else { + fprintf(bitfile, "%%%%CreationDate: %s", + asctime(gmtime(&jobtime))); + } #endif if (! isepsf) { /* -- cgit v1.2.3