X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftime%2Fstrptime.c;h=f41f55f24cf4bcf8a100178440a15e8efdfc14ad;hb=efa9d396f9d3af6c6f85ec86302b48206c574a38;hp=488c08dd657aaca737a14659ef045469162085e9;hpb=5989dde3459b2ccd304f89e3e875136e5608b8ff;p=oweals%2Fmusl.git diff --git a/src/time/strptime.c b/src/time/strptime.c index 488c08dd..f41f55f2 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -7,17 +6,19 @@ #include #include -char *strptime(const char *s, const char *f, struct tm *tm) +char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) { - int i, w, neg, adj, min, range, *dest; + int i, w, neg, adj, min, range, *dest, dummy; const char *ex; size_t len; + int want_century = 0, century = 0; while (*f) { if (*f != '%') { if (isspace(*f)) for (; *s && isspace(*s); s++); else if (*s != *f) return 0; else s++; f++; + continue; } f++; if (*f == '+') f++; @@ -40,6 +41,10 @@ char *strptime(const char *s, const char *f, struct tm *tm) if (!s) return 0; break; case 'C': + dest = ¢ury; + if (w<0) w=2; + want_century |= 2; + goto numeric_digits; case 'd': case 'e': dest = &tm->tm_mday; min = 1; @@ -112,8 +117,11 @@ char *strptime(const char *s, const char *f, struct tm *tm) break; case 'U': case 'W': - //FIXME - return 0; + /* Throw away result, for now. (FIXME?) */ + dest = &dummy; + min = 0; + range = 54; + goto numeric_range; case 'w': dest = &tm->tm_wday; min = 0; @@ -128,16 +136,21 @@ char *strptime(const char *s, const char *f, struct tm *tm) if (!s) return 0; break; case 'y': - //FIXME - return 0; + dest = &tm->tm_year; + w = 2; + want_century |= 1; + goto numeric_digits; case 'Y': dest = &tm->tm_year; if (w<0) w=4; adj = 1900; + want_century = 0; goto numeric_digits; case '%': if (*s++ != '%') return 0; break; + default: + return 0; numeric_range: if (!isdigit(*s)) return 0; *dest = 0; @@ -165,6 +178,7 @@ char *strptime(const char *s, const char *f, struct tm *tm) ex = nl_langinfo(min+i); len = strlen(ex); if (strncasecmp(s, ex, len)) continue; + s += len; *dest = i % range; break; } @@ -175,5 +189,9 @@ char *strptime(const char *s, const char *f, struct tm *tm) ; } } + if (want_century) { + if (want_century & 2) tm->tm_year += century * 100 - 1900; + else if (tm->tm_year <= 68) tm->tm_year += 100; + } return (char *)s; }