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
This commit is contained in:
ache 2014-10-19 21:16:24 +00:00
parent 525f95cd64
commit 537ec842e6

View File

@ -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 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
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 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
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);
}