chiark / gitweb /
Handle SOURCE_DATE_EPOCH in unsigned long long, not unitmax_t
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 27 Feb 2025 22:48:52 +0000 (22:48 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 27 Feb 2025 22:48:52 +0000 (22:48 +0000)
unsigned long long is guaranteed to be big enough.  No need to go
bigger.

bedstead.c

index fe87a1a89b1e0084aee4ff6c1fd7af65f127038e..a4f30e41cf9490571eb6ab93669d3f79e8bac0cf 100644 (file)
@@ -99,7 +99,6 @@
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
-#include <inttypes.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -3145,26 +3144,26 @@ static char *
 time_for_ttx(void)
 {
        struct tm *timeptr, tm;
-       uintmax_t epochumax;
+       unsigned long long epochull;
        char *epochstr, *endptr, *timestr;
 
        /* Work out what timestamp to use. */
        if ((epochstr = getenv("SOURCE_DATE_EPOCH")) != NULL) {
                errno = 0;
-               epochumax = strtoumax(epochstr, &endptr, 10);
+               epochull = strtoull(epochstr, &endptr, 10);
                if (!isdigit((unsigned char)epochstr[0]) ||
                    endptr == epochstr || *endptr != '\0' ||
                    errno == ERANGE ||
                    /* Allow years up to 9999. */
-                   epochumax >= 253402300800) {
+                   epochull >= 253402300800) {
                        fprintf(stderr, "Invalid SOURCE_DATE_EPOCH\n");
                        return NULL;
                }
                tm.tm_isdst = -1;
-               tm.tm_sec = epochumax % 60;
-               tm.tm_min = epochumax / 60 % 60;
-               tm.tm_hour = epochumax / 3600 % 24;
-               long day = epochumax / 86400;
+               tm.tm_sec = epochull % 60;
+               tm.tm_min = epochull / 60 % 60;
+               tm.tm_hour = epochull / 3600 % 24;
+               long day = epochull / 86400;
                tm.tm_wday = (day + 4) % 7; /* 1970-01-01 was a Thursday. */
                int y = 1970 + (day / 146097) * 400;
                day = day % 146097;