Skip to content

Commit 21cebf4

Browse files
authored
Supporting SOURCE_DATE_EPOCH environment variable
Credits https://reproducible-builds.org/docs/source-date-epoch/
1 parent 8aaf80c commit 21cebf4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,17 @@ static inline rk_time getTime(bool reproducible) {
14041404
rkTime.second = 00;
14051405
} else {
14061406
struct tm *tm;
1407-
time_t tt = time(NULL);
1407+
time_t tt;
1408+
time_t now;
1409+
char *source_date_epoch;
1410+
/* This assumes that the SOURCE_DATE_EPOCH environment variable will contain
1411+
a correct, positive integer in the time_t range */
1412+
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
1413+
(now = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0)
1414+
tt = time(&now);
1415+
else
1416+
tt = time(NULL);
1417+
14081418
tm = localtime(&tt);
14091419
rkTime.year = tm->tm_year + 1900;
14101420
rkTime.month = tm->tm_mon + 1;

0 commit comments

Comments
 (0)