logo

utils-std

Collection of commonly available Unix tools
commit: dda0ccc3b22f441bec530b1d7a0f158ffeef3f9c
parent 7952b8cac08004a427072cd04b2214286bcca353
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 28 Mar 2024 18:59:38 +0100

lib/strtodur: assert(errno == 0)

Diffstat:

Mlib/strtodur.c6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/strtodur.c b/lib/strtodur.c @@ -23,7 +23,7 @@ strtodur(char *s, struct timespec *dur) int parsed = 0; if(s[0] != '.' && s[0] != ',') { - errno = 0; + assert(errno == 0); int ret = sscanf(s, "%10ld%n", &dur->tv_sec, &parsed); if(ret < 1) { @@ -34,6 +34,7 @@ strtodur(char *s, struct timespec *dur) else { perror("strtodur: Error with sscanf"); + errno = 0; } return -1; } @@ -50,7 +51,7 @@ strtodur(char *s, struct timespec *dur) if(s[0] == ',') s[0] = '.'; parsed = 0; - errno = 0; + assert(errno == 0); if(sscanf(s, "%10f%n", &fraction, &parsed) < 1) { if(errno == 0) @@ -60,6 +61,7 @@ strtodur(char *s, struct timespec *dur) else { perror("strtodur: Error with sscanf"); + errno = 0; } return -1; }