mirror of
https://bjh21.me.uk/bedstead/.git
synced 2026-08-06 12:24:27 -04:00
Handle SOURCE_DATE_EPOCH in unsigned long long, not unitmax_t
unsigned long long is guaranteed to be big enough. No need to go bigger.
This commit is contained in:
parent
60136bf337
commit
528c0542ed
15
bedstead.c
15
bedstead.c
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user