diff options
author | ache <ache@FreeBSD.org> | 2014-10-19 21:16:24 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2014-10-19 21:16:24 +0000 |
commit | 537ec842e6dfb2dd7dba5c5a4999f602df10bf4f (patch) | |
tree | 4972eca42afa3e8ba921b8ef9f2ea2963c55cf5c /lib/libc/stdtime/strptime.c | |
parent | 525f95cd64eb5b3807691def3dd866b81a373563 (diff) | |
download | FreeBSD-src-537ec842e6dfb2dd7dba5c5a4999f602df10bf4f.zip FreeBSD-src-537ec842e6dfb2dd7dba5c5a4999f602df10bf4f.tar.gz |
MFC r272562,r272678,r272679
1) Fix the case we have less arguments for format string than we expected.
2) Return error on unsupported format specs.
(both according to POSIX)
3) For %Z format, understand "UTC" name too.
PR: 93197
Diffstat (limited to 'lib/libc/stdtime/strptime.c')
-rw-r--r-- | lib/libc/stdtime/strptime.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 8576bdb..2be6358 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -103,9 +103,6 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, ptr = fmt; while (*ptr != 0) { - if (*buf == 0) - break; - c = *ptr++; if (c != '%') { @@ -123,7 +120,6 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, label: c = *ptr++; switch (c) { - case 0: case '%': if (*buf++ != '%') return (NULL); @@ -552,7 +548,8 @@ label: strncpy(zonestr, buf, cp - buf); zonestr[cp - buf] = '\0'; tzset(); - if (0 == strcmp(zonestr, "GMT")) { + if (0 == strcmp(zonestr, "GMT") || + 0 == strcmp(zonestr, "UTC")) { *GMTp = 1; } else if (0 == strcmp(zonestr, tzname[0])) { tm->tm_isdst = 0; @@ -599,6 +596,9 @@ label: while (isspace_l((unsigned char)*buf, locale)) buf++; break; + + default: + return (NULL); } } @@ -674,6 +674,7 @@ strptime_l(const char * __restrict buf, const char * __restrict fmt, ret = _strptime(buf, fmt, tm, &gmt, loc); if (ret && gmt) { time_t t = timegm(tm); + localtime_r(&t, tm); } |