]> git.ipfire.org Git - pakfire.git/commitdiff
string: Fix error handling for strftime functions
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Feb 2025 17:38:48 +0000 (17:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Feb 2025 17:38:48 +0000 (17:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/string.c

index f75084465c958aaa20e3b6e397ec97d0c21156da..31aea9562e807380674f18f49d1b2db778cbb234 100644 (file)
@@ -632,13 +632,14 @@ int __pakfire_format_speed(char* dst, size_t length, double value) {
 
 int __pakfire_strftime(char* buffer, const size_t length,
                const char* format, const time_t t) {
-       struct tm* tm = gmtime(&t);
        int r;
 
+       struct tm* tm = gmtime(&t);
+
        // Format time
        r = strftime(buffer, length, format, tm);
-       if (r == 0)
-               return 1;
+       if (r < 0)
+               return -errno;
 
        return 0;
 }
@@ -647,7 +648,7 @@ int __pakfire_strftime_now(char* buffer, size_t length, const char* format) {
        // Fetch the current time
        const time_t t = time(NULL);
        if (t < 0)
-               return 1;
+               return -errno;
 
        return __pakfire_strftime(buffer, length, format, t);
 }