File: 035-source-date-epoch.patch

Image for: File: 035-source-date-epoch.patch
package info (click to toggle)
man2html 1.6g-9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,724 kB
  • ctags: 3,346
  • sloc: ansic: 9,667; sh: 2,309; perl: 335; makefile: 327; awk: 305; lisp: 171; cs: 170; xml: 119
file content (66 lines) | stat: -rw-r--r-- 2,189 bytes parent folder | download | duplicates (2)
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
From: Maria Valentina Marin <marivalenm@gmail.com>
Date: Wed, 19 Aug 2015 17:51:02 +0000
Subject: 0035 source date epoch

Make man2html use the latest date in debian/changelog as the timestamp for its 
html output if $SOURCE_DATE_EPOCH is exported. Otherwise man2html continues with
its default behaviour of using the date of today to produce its timestamps.

Bug-Debian: https://bugs.debian.org/796130
---
 man2html/cgibase.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/man2html/cgibase.c b/man2html/cgibase.c
index b296c1d..a677473 100644
--- a/man2html/cgibase.c
+++ b/man2html/cgibase.c
@@ -8,6 +8,8 @@
 #include <ctype.h>		/* tolower() */
 #include <string.h>		/* strlen() */
 #include "defs.h"
+#include <errno.h>
+#include <limits.h>
 
 /*
  * The default is to use cgibase. With relative html style
@@ -83,11 +85,39 @@ void print_sig()
     char timebuf[TIMEBUFSZ];
     struct tm *timetm;
     time_t now;
+    char *source_date_epoch;
+    unsigned long long epoch;
+    char *endptr;
 
     timebuf[0] = 0;
 #ifdef TIMEFORMAT
     sprintf(timebuf, "Time: ");
+    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));
+			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);
+		}
+		now=epoch;
+	}
+	else {
     now=time(NULL);
+	}
     timetm=gmtime(&now);
     strftime(timebuf+6, TIMEBUFSZ-6, TIMEFORMAT, timetm);
     timebuf[TIMEBUFSZ-1] = 0;