1 Description: Allow the build timestamp to be externally set
2 In order to make Ghostscript output reproducible, we need a way to
3 set the build timestamp to other values than the current time.
4 We now consistently use gp_get_realtime() instead of directly calling
5 time() or gp_get_usertime() and make gp_get_realtime() use the value
6 found in the SOURCE_DATE_EPOCH environment variable if set. Also,
7 environment timezone is fixed to UTC if SOURCE_DATE_EPOCH is used to
9 Author: Eduard Sanou <dhole@openmailbox.org>
10 Author: Peter De Wachter <pdewacht@gmail.com>
11 Bug-Debian: https://bugs.debian.org/794004
12 Last-Update: 2015-07-30
14 This patch header follows DEP-3: https://dep.debian.net/deps/dep3/
19 # include "windows_.h"
26 gp_get_realtime(long *pdt)
31 #if gettimeofday_no_timezone /* older versions of SVR4 */
37 + env = getenv("SOURCE_DATE_EPOCH");
43 + timestamp = strtol(env, &end, 10);
44 + if (env == end || *end || errno != 0) {
45 + lprintf("Ghostscript: SOURCE_DATE_EPOCH is not a number!\n");
49 + tp.tv_sec = timestamp;
52 + /* We need to fix the environment timezone to get reproducible */
53 + /* results when parsing the result of gp_get_realtime. */
54 + setenv("TZ", "UTC", 1);
57 /* tp.tv_sec is #secs since Jan 1, 1970 */
60 --- a/devices/vector/gdevpdf.c
61 +++ b/devices/vector/gdevpdf.c
68 char buf[1+2+4+2+2+2+2+2+1+2+1+2+1+1+1]; /* (D:yyyymmddhhmmssZhh'mm')\0 */
75 + gp_get_realtime(secs_ns);
79 timeoffset = (int)difftime(t, mktime(&tms)); /* tz+dst in seconds */
80 --- a/devices/vector/gdevpdfe.c
81 +++ b/devices/vector/gdevpdfe.c
84 /* We don't write a day time because we don't have a time zone. */
88 char buf1[4+1+2+1+2+1]; /* yyyy-mm-dd\0 */
91 memset(&t, 0, sizeof(t));
92 memset(&tms, 0, sizeof(tms));
95 + gp_get_realtime(secs_ns);
100 --- a/devices/vector/gdevpsu.c
101 +++ b/devices/vector/gdevpsu.c
103 fprintf(f, "%%%%Creator: %s %ld (%s)\n", gs_product, (long)gs_revision,
111 memset(&t, 0, sizeof(t));
112 memset(&tms, 0, sizeof(tms));
115 + gp_get_realtime(secs_ns);
117 tms = *localtime(&t);
119 fprintf(f, "%%%%CreationDate: %d/%02d/%02d %02d:%02d:%02d\n",