]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
authorAlejandro Colomar <alx@kernel.org>
Tue, 18 Feb 2025 14:24:34 +0000 (15:24 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 2 Jun 2025 07:59:51 +0000 (09:59 +0200)
If it fails, let's fall back to get_date().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/strtoday.c

index c0b159337b3ecd1c57793cf6e7828237f215aea1..cf77ca6fa3fe1d520812ae96ffc9f82b91639eab 100644 (file)
 #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) {