From: Alejandro Colomar Date: Tue, 18 Feb 2025 14:24:34 +0000 (+0100) Subject: lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly X-Git-Tag: 4.18.0-rc1~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3d7812eb731de2420c05331da013ece1652a75a9;p=thirdparty%2Fshadow.git lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly If it fails, let's fall back to get_date(). Signed-off-by: Alejandro Colomar --- diff --git a/lib/strtoday.c b/lib/strtoday.c index c0b159337..cf77ca6fa 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -14,18 +14,15 @@ #include "atoi/str2i.h" #include "getdate.h" #include "prototypes.h" -#include "string/ctype/strisascii/strisdigit.h" #include "string/strcmp/streq.h" -#include "string/strcmp/strprefix.h" -#include "string/strspn/stpspn.h" // string parse-to day-since-Epoch long strtoday(const char *str) { + long d; time_t t; - const char *s = str; /* * get_date() interprets an empty string as the current date, @@ -39,15 +36,8 @@ strtoday(const char *str) /* If a numerical value is provided, this is already a number of * days since EPOCH. */ - s = strprefix(s, "-") ?: s; - s = stpspn(s, " "); - if (strisdigit(s)) { - long retdate; - - if (str2sl(&retdate, str) == -1) - return -2; - return retdate; - } + if (str2sl(&d, str) == 0) + return d; t = get_date(str); if ((time_t) - 1 == t) {