diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-11-03 23:04:44 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-11-03 23:05:13 -0700 |
commit | 870a155fc6f4dcfb438ba1ce9aff86c0c1043f2a (patch) | |
tree | 023cbbd57ac3fed3b6ff958b1b9e6f1ee190f8da | |
parent | c8bc4bf97dc982ba88f33ccf829a579425dfb9ac (diff) | |
download | gnulib-870a155fc6f4dcfb438ba1ce9aff86c0c1043f2a.tar.gz |
posixtm: simplify test for mktime failure
* lib/posixtm.c (posixtime): Simplify.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | lib/posixtm.c | 26 |
2 files changed, 12 insertions, 17 deletions
@@ -1,5 +1,8 @@ 2018-11-03 Paul Eggert <eggert@cs.ucla.edu> + posixtm: simplify test for mktime failure + * lib/posixtm.c (posixtime): Simplify. + nstrftime: simplify test for mktime failure * lib/nstrftime.c (__strftime_internal): Simplify. diff --git a/lib/posixtm.c b/lib/posixtm.c index 4e8125cc7a..b3934b0ec1 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -176,7 +176,6 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits) { struct tm tm0; struct tm tm1; - struct tm const *tm; time_t t; if (! posix_time_parse (&tm0, s, syntax_bits)) @@ -188,30 +187,23 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits) tm1.tm_mday = tm0.tm_mday; tm1.tm_mon = tm0.tm_mon; tm1.tm_year = tm0.tm_year; + tm1.tm_wday = -1; tm1.tm_isdst = -1; t = mktime (&tm1); - if (t != (time_t) -1) - tm = &tm1; - else - { - /* mktime returns -1 for errors, but -1 is also a valid time_t - value. Check whether an error really occurred. */ - tm = localtime (&t); - if (! tm) - return false; - } + if (tm1.tm_wday < 0) + return false; /* Reject dates like "September 31" and times like "25:61". However, allow a seconds count of 60 even in time zones that do not support leap seconds, treating it as the following second; POSIX requires this. */ - if ((tm0.tm_year ^ tm->tm_year) - | (tm0.tm_mon ^ tm->tm_mon) - | (tm0.tm_mday ^ tm->tm_mday) - | (tm0.tm_hour ^ tm->tm_hour) - | (tm0.tm_min ^ tm->tm_min) - | (tm0.tm_sec ^ tm->tm_sec)) + if ((tm0.tm_year ^ tm1.tm_year) + | (tm0.tm_mon ^ tm1.tm_mon) + | (tm0.tm_mday ^ tm1.tm_mday) + | (tm0.tm_hour ^ tm1.tm_hour) + | (tm0.tm_min ^ tm1.tm_min) + | (tm0.tm_sec ^ tm1.tm_sec)) { /* Any mismatch without 60 in the tm_sec field is invalid. */ if (tm0.tm_sec != 60) |