From: Alejandro Colomar Date: Tue, 18 Feb 2025 22:37:17 +0000 (+0100) Subject: lib/strtoday.c: Actually return a date from get_date() X-Git-Tag: 4.18.0-rc1~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69762b6a9dc6bcd47257134b3e357e6f55a1d658;p=thirdparty%2Fshadow.git lib/strtoday.c: Actually return a date from get_date() Signed-off-by: Alejandro Colomar --- diff --git a/lib/strtoday.c b/lib/strtoday.c index ea327faee..ac3be8000 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -18,7 +18,8 @@ #include "string/strcmp/streq.h" -static time_t get_date(const char *s); +static long get_date(const char *s); +static long dategm(struct tm *tm); // string parse-to day-since-Epoch @@ -26,7 +27,6 @@ long strtoday(const char *str) { long d; - time_t t; if (NULL == str || streq(str, "")) return -1; @@ -37,15 +37,15 @@ strtoday(const char *str) if (str2sl(&d, str) == 0) return d; - t = get_date(str); - if ((time_t) - 1 == t) { + d = get_date(str); + if (d == -1) return -2; - } - return t / DAY; + + return d; } -static time_t +static long get_date(const char *s) { time_t t; @@ -60,5 +60,18 @@ get_date(const char *s) if (p == NULL || !streq(p, "")) return -1; - return timegm(&tm); + return dategm(&tm); +} + + +static long +dategm(struct tm *tm) +{ + time_t t; + + t = timegm(tm); + if (t == (time_t) -1) + return -1; + + return t / DAY; }