-
-
Save lamby/f8215f49983f8e3c7309300e26cfb777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ikarus-0.0.3+bzr.2010.01.26.orig/src/ikarus-runtime.c | |
+++ ikarus-0.0.3+bzr.2010.01.26/src/ikarus-runtime.c | |
@@ -810,8 +810,36 @@ ikptr | |
ikrt_bvftime(ikptr outbv, ikptr fmtbv){ | |
time_t t; | |
struct tm* tmp; | |
- t = time(NULL); | |
- tmp = localtime(&t); | |
+ char *endptr; | |
+ char *source_date_epoch; | |
+ unsigned long long 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) { | |
+ printf(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); | |
+ } | |
+ t = epoch; | |
+ } else { | |
+ t = time(NULL); | |
+ } | |
+ tmp = gmtime(&t); | |
if(tmp == NULL){ | |
fprintf(stderr, "Error in time: %s\n", strerror(errno)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment