archrelease: copy trunk to extra-x86_64
[arch-packages.git] / ghostscript / trunk / 2010_add_build_timestamp_setting.patch
blob1713685e0dd3fa3fb0326823016be638803c3898
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
8 avoid variations.
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
13 ---
14 This patch header follows DEP-3: https://dep.debian.net/deps/dep3/
15 --- a/base/gp_unix.c
16 +++ b/base/gp_unix.c
17 @@ -19,6 +19,7 @@
18 #ifdef __MINGW32__
19 # include "windows_.h"
20 #endif
21 +#include "errno_.h"
22 #include "pipe_.h"
23 #include "string_.h"
24 #include "time_.h"
25 @@ -148,6 +149,7 @@
26 gp_get_realtime(long *pdt)
28 struct timeval tp;
29 + const char *env;
31 #if gettimeofday_no_timezone /* older versions of SVR4 */
33 @@ -167,6 +169,26 @@
35 #endif
37 + env = getenv("SOURCE_DATE_EPOCH");
38 + if (env) {
39 + char *end;
40 + long timestamp;
42 + errno = 0;
43 + timestamp = strtol(env, &end, 10);
44 + if (env == end || *end || errno != 0) {
45 + lprintf("Ghostscript: SOURCE_DATE_EPOCH is not a number!\n");
46 + timestamp = 0;
47 + }
49 + tp.tv_sec = timestamp;
50 + tp.tv_usec = 0;
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);
55 + }
57 /* tp.tv_sec is #secs since Jan 1, 1970 */
58 pdt[0] = tp.tv_sec;
60 --- a/devices/vector/gdevpdf.c
61 +++ b/devices/vector/gdevpdf.c
62 @@ -427,6 +427,7 @@
65 struct tm tms;
66 + long secs_ns[2];
67 time_t t;
68 char buf[1+2+4+2+2+2+2+2+1+2+1+2+1+1+1]; /* (D:yyyymmddhhmmssZhh'mm')\0 */
69 int timeoffset;
70 @@ -438,7 +439,8 @@
71 timesign = 'Z';
72 timeoffset = 0;
73 #else
74 - time(&t);
75 + gp_get_realtime(secs_ns);
76 + t = secs_ns[0];
77 tms = *gmtime(&t);
78 tms.tm_isdst = -1;
79 timeoffset = (int)difftime(t, mktime(&tms)); /* tz+dst in seconds */
80 --- a/devices/vector/gdevpdfe.c
81 +++ b/devices/vector/gdevpdfe.c
82 @@ -199,6 +199,7 @@
84 /* We don't write a day time because we don't have a time zone. */
85 struct tm tms;
86 + long secs_ns[2];
87 time_t t;
88 char buf1[4+1+2+1+2+1]; /* yyyy-mm-dd\0 */
90 @@ -206,7 +207,8 @@
91 memset(&t, 0, sizeof(t));
92 memset(&tms, 0, sizeof(tms));
93 #else
94 - time(&t);
95 + gp_get_realtime(secs_ns);
96 + t = secs_ns[0];
97 tms = *localtime(&t);
98 #endif
99 gs_sprintf(buf1,
100 --- a/devices/vector/gdevpsu.c
101 +++ b/devices/vector/gdevpsu.c
102 @@ -183,6 +183,7 @@
103 fprintf(f, "%%%%Creator: %s %ld (%s)\n", gs_product, (long)gs_revision,
104 dev->dname);
106 + long secs_ns[2];
107 time_t t;
108 struct tm tms;
110 @@ -190,7 +191,8 @@
111 memset(&t, 0, sizeof(t));
112 memset(&tms, 0, sizeof(tms));
113 #else
114 - time(&t);
115 + gp_get_realtime(secs_ns);
116 + t = secs_ns[0];
117 tms = *localtime(&t);
118 #endif
119 fprintf(f, "%%%%CreationDate: %d/%02d/%02d %02d:%02d:%02d\n",