Honour an external definition of SOURCE_DATE_EPOCH when updating the embedded modification date in TTF/TTC files. --- a/lib/tatime.c +++ b/lib/tatime.c @@ -15,6 +15,8 @@ #include #include +#include +#include #include "ta.h" @@ -27,12 +29,51 @@ TA_get_current_time(FT_ULong* high, { /* there have been 24107 days between January 1st, 1904 (the epoch of */ /* OpenType), and January 1st, 1970 (the epoch of the `time' function) */ - TA_ULongLong seconds_to_1970 = 24107 * 24 * 60 * 60; - TA_ULongLong seconds_to_today = seconds_to_1970 + (TA_ULongLong)time(NULL); + const TA_ULongLong seconds_to_1970 = 24107 * 24 * 60 * 60; + TA_ULongLong seconds_to_build; + time_t now; + char *source_date_epoch, *endptr; + TA_ULongLong epoch; + 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); + } - *high = (FT_ULong)(seconds_to_today >> 32); - *low = (FT_ULong)seconds_to_today; + seconds_to_build = seconds_to_1970 + (TA_ULongLong)now; + + *high = (FT_ULong)(seconds_to_build >> 32); + *low = (FT_ULong)seconds_to_build; } /* end of tatime.c */ '>AgeCommit message (Expand)Author 2019-11-09doc: Mention value /var to localstatedir option....zimoun 2019-09-04doc: Update 'README'....Ludovic Courtès 2019-01-09build: Require Guile 2.2....Ludovic Courtès 2018-12-02Make Guile-JSON a required dependency....Eric Bavier 2018-11-23Update Guile-SQLite3 URL everywhere....Ludovic Courtès 2018-09-04Switch to Guile-Gcrypt....Ludovic Courtès 2018-06-27doc: Specify Guile-SQLite3 minimum version....Ludovic Courtès 2018-06-14build: Require Guile-SQLite3....Ludovic Courtès 2018-02-26build: Require Guile >= 2.0.13....Ludovic Courtès 2018-01-07doc: Mark zlib as mandatory, libbz2 as optional....Ludovic Courtès 2018-01-01doc: Update requirements in 'README'....Mathieu Lirzin 2017-09-25README: Replace http:// with https:// where applicable.Marius Bakke 2017-03-18build: Require Guile >= 2.0.9....Ludovic Courtès 2017-01-30maint: Fix invalid calls to 'info'....Mathieu Lirzin 22-08-30 08:50:44 +0200'>2022-08-30bootloader: Add device-tree-support? option....Reza Alizadeh Majd 2022-06-24image: Add support for 32bit UEFI....Denis 'GNUtoo' Carikli 2022-06-06bootloader: grub: Add removable grub-efi bootloader option....Karl Hallsby