gnu: kio: Search 'smbd' on $PATH.
[jackhill/guix/guix.git] / gnu / packages / patches / ttfautohint-source-date-epoch.patch
CommitLineData
1e69db8f
EB
1Honour an external definition of SOURCE_DATE_EPOCH when updating the embedded
2modification date in TTF/TTC files.
3
4--- a/lib/tatime.c
5+++ b/lib/tatime.c
6@@ -15,6 +15,8 @@
7
8 #include <time.h>
9 #include <stdint.h>
10+#include <errno.h>
11+#include <limits.h>
12
13 #include "ta.h"
14
15@@ -27,12 +29,51 @@ TA_get_current_time(FT_ULong* high,
16 {
17 /* there have been 24107 days between January 1st, 1904 (the epoch of */
18 /* OpenType), and January 1st, 1970 (the epoch of the `time' function) */
19- TA_ULongLong seconds_to_1970 = 24107 * 24 * 60 * 60;
20- TA_ULongLong seconds_to_today = seconds_to_1970 + (TA_ULongLong)time(NULL);
21+ const TA_ULongLong seconds_to_1970 = 24107 * 24 * 60 * 60;
22+ TA_ULongLong seconds_to_build;
23
24+ time_t now;
25+ char *source_date_epoch, *endptr;
26+ TA_ULongLong epoch;
27+ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
28+ if (source_date_epoch) {
29+ errno = 0;
30+ epoch = strtoull(source_date_epoch, &endptr, 10);
31+ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
32+ || (errno != 0 && epoch == 0)) {
33+ fprintf(stderr,
34+ "Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n",
35+ strerror(errno));
36+ exit(EXIT_FAILURE);
37+ }
38+ if (endptr == source_date_epoch) {
39+ fprintf(stderr,
40+ "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n",
41+ endptr);
42+ exit(EXIT_FAILURE);
43+ }
44+ if (*endptr != '\0') {
45+ fprintf(stderr,
46+ "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
47+ endptr);
48+ exit(EXIT_FAILURE);
49+ }
50+ if (epoch > ULONG_MAX) {
51+ fprintf(stderr,
52+ "Environment variable $SOURCE_DATE_EPOCH: value must be smaller "
53+ "than or equal to: %lu but was found to be: %llu \n",
54+ ULONG_MAX, epoch);
55+ exit(EXIT_FAILURE);
56+ }
57+ now = epoch;
58+ } else {
59+ now = time(NULL);
60+ }
61
62- *high = (FT_ULong)(seconds_to_today >> 32);
63- *low = (FT_ULong)seconds_to_today;
64+ seconds_to_build = seconds_to_1970 + (TA_ULongLong)now;
65+
66+ *high = (FT_ULong)(seconds_to_build >> 32);
67+ *low = (FT_ULong)seconds_to_build;
68 }
69
70 /* end of tatime.c */