]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/strtoday.c: Actually return a date from get_date()
authorAlejandro Colomar <alx@kernel.org>
Tue, 18 Feb 2025 22:37:17 +0000 (23:37 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 2 Jun 2025 07:59:51 +0000 (09:59 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/strtoday.c

index ea327faeeeb455b241edc1851d7b325eca03d1c0..ac3be80006d99518d40f847cc56f85c7b0f8cb43 100644 (file)
@@ -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;
 }