chiark / gitweb /
Further SOURCE_DATE_EPOCH simplification
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 27 Feb 2025 23:00:24 +0000 (23:00 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 27 Feb 2025 23:00:24 +0000 (23:00 +0000)
Rather than mucking about with errno, we can just take advantage of the
fact that on overflow, strtoull() is specified to return ULLONG_MAX,
which is guaranteed to be (much) bigger than the maximum
SOURCE_DATE_EPOCH that we can cope with.  So our usual range check can
cope with overflow as well.

bedstead.c

index a4f30e41cf9490571eb6ab93669d3f79e8bac0cf..e0b12af9ad5352f2ec8c578b8639227bf96d7267 100644 (file)
@@ -98,7 +98,6 @@
 
 #include <assert.h>
 #include <ctype.h>
-#include <errno.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -3149,11 +3148,9 @@ time_for_ttx(void)
 
        /* Work out what timestamp to use. */
        if ((epochstr = getenv("SOURCE_DATE_EPOCH")) != NULL) {
-               errno = 0;
                epochull = strtoull(epochstr, &endptr, 10);
                if (!isdigit((unsigned char)epochstr[0]) ||
                    endptr == epochstr || *endptr != '\0' ||
-                   errno == ERANGE ||
                    /* Allow years up to 9999. */
                    epochull >= 253402300800) {
                        fprintf(stderr, "Invalid SOURCE_DATE_EPOCH\n");