logo

utils-std

Collection of commonly available Unix tools
commit: d1ec7315a915f5316e669b7abe4cb827ced28469
parent b51da2a6cc5143174522ba123e8d05012d9d7355
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 28 Mar 2024 18:56:56 +0100

lib/iso_parse: assert(errno == 0)

Diffstat:

Mlib/iso_parse.c8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/iso_parse.c b/lib/iso_parse.c @@ -6,6 +6,7 @@ #define _XOPEN_SOURCE 700 // strptime (NetBSD) #define _POSIX_C_SOURCE 200809L // st_atim/st_mtim +#include <assert.h> #include <ctype.h> /* isdigit */ #include <errno.h> /* errno */ #include <stdio.h> /* perror, sscanf */ @@ -25,8 +26,8 @@ iso_parse(char *arg, char **errstr) if(arg[0] == '@') { arg++; - errno = 0; + assert(errno == 0); time.tv_sec = strtol(arg, NULL, 10); if(errno != 0) { @@ -68,7 +69,7 @@ iso_parse(char *arg, char **errstr) if(s[0] == ',') s[0] = '.'; - errno = 0; + assert(errno == 0); if(sscanf(s, "%10lf%n", &fraction, &parsed) < 1) { if(errno == 0) @@ -78,6 +79,7 @@ iso_parse(char *arg, char **errstr) else { *errstr = strerror(errno); + errno = 0; } return time; } @@ -99,10 +101,12 @@ iso_parse(char *arg, char **errstr) tm.tm_zone = "UTC"; } + assert(errno == 0); time.tv_sec = mktime(&tm); if(time.tv_sec == (time_t)-1) { *errstr = strerror(errno); + errno = 0; return time; }