From: Thomas Weißschuh Date: Fri, 20 Jan 2023 02:06:04 +0000 (+0000) Subject: lib/timeutils: parse_timestamp: allow fixed reference time X-Git-Tag: v2.39-rc1~125^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15a1f536a8d31c8fac9eb0be420502773d703319;p=thirdparty%2Futil-linux.git lib/timeutils: parse_timestamp: allow fixed reference time Signed-off-by: Thomas Weißschuh --- diff --git a/lib/timeutils.c b/lib/timeutils.c index 4eaef9533a..c474d750cb 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -147,7 +147,7 @@ static int parse_sec(const char *t, usec_t *usec) return 0; } -int parse_timestamp(const char *t, usec_t *usec) +static int parse_timestamp_reference(time_t x, const char *t, usec_t *usec) { static const struct { const char *name; @@ -171,7 +171,6 @@ int parse_timestamp(const char *t, usec_t *usec) const char *k; struct tm tm, copy; - time_t x; usec_t plus = 0, minus = 0, ret; int r, weekday = -1; unsigned i; @@ -198,7 +197,6 @@ int parse_timestamp(const char *t, usec_t *usec) assert(t); assert(usec); - x = time(NULL); localtime_r(&x, &tm); tm.tm_isdst = -1; @@ -354,6 +352,11 @@ int parse_timestamp(const char *t, usec_t *usec) return 0; } +int parse_timestamp(const char *t, usec_t *usec) +{ + return parse_timestamp_reference(time(NULL), t, usec); +} + /* Returns the difference in seconds between its argument and GMT. If if TP is * invalid or no DST information is available default to UTC, that is, zero. * tzset is called so, for example, 'TZ="UTC" hwclock' will work as expected.