commit: ccba48bb598c467cd43fbae317d84900fd5819dc
parent e6b939494b67612367eabf8bf9a22de1c8220daf
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 29 Mar 2024 02:10:55 +0100
lib/iso_parse: Reset errno after setting *errstr
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/iso_parse.c b/lib/iso_parse.c
@@ -32,6 +32,7 @@ iso_parse(char *arg, char **errstr)
if(errno != 0)
{
*errstr = strerror(errno);
+ errno = 0;
return time;
}
return time;
@@ -53,11 +54,13 @@ iso_parse(char *arg, char **errstr)
if(s == NULL)
{
*errstr = "strptime(…, \"%Y-%m-%d\", …) returned NULL";
+ errno = 0;
return time;
}
if(s[0] != 'T' && s[0] != ' ')
{
*errstr = "Couldn't find time-separator (T or space) after date (Y-m-d)";
+ errno = 0;
return time;
}
s++;
@@ -66,6 +69,7 @@ iso_parse(char *arg, char **errstr)
if(s == NULL)
{
*errstr = "strptime(…, \"%H:%M:%S\", …) returned NULL";
+ errno = 0;
return time;
}
@@ -110,10 +114,14 @@ iso_parse(char *arg, char **errstr)
assert(errno == 0);
time.tv_sec = mktime(&tm);
- if(time.tv_sec == (time_t)-1)
+ if(time.tv_sec == (time_t)-1 || errno != 0)
{
- *errstr = strerror(errno);
- errno = 0;
+ if(errno == EOVERFLOW)
+ *errstr = "result couldn't be represented (EOVERFLOW)";
+ else
+ *errstr = strerror(errno);
+
+ errno = 0;
return time;
}