9 char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
11 int i, w, neg, adj, min, range, *dest, dummy;
14 int want_century = 0, century = 0;
17 if (isspace(*f)) for (; *s && isspace(*s); s++);
18 else if (*s != *f) return 0;
27 w=strtoul(f, &new_f, 10);
39 case 'b': case 'B': case 'h':
45 s = strptime(s, nl_langinfo(D_T_FMT), tm);
59 s = strptime(s, "%m/%d/%y", tm);
90 for (; *s && isspace(*s); s++);
93 ex = nl_langinfo(AM_STR);
95 if (!strncasecmp(s, ex, len)) {
99 ex = nl_langinfo(PM_STR);
101 if (!strncasecmp(s, ex, len)) {
108 s = strptime(s, nl_langinfo(T_FMT_AMPM), tm);
112 s = strptime(s, "%H:%M", tm);
121 s = strptime(s, "%H:%M:%S", tm);
126 /* Throw away result, for now. (FIXME?) */
137 s = strptime(s, nl_langinfo(D_FMT), tm);
141 s = strptime(s, nl_langinfo(T_FMT), tm);
156 if (*s++ != '%') return 0;
161 if (!isdigit(*s)) return 0;
163 for (i=1; i<=min+range && isdigit(*s); i*=10)
164 *dest = *dest * 10 + *s++ - '0';
165 if (*dest - min >= (unsigned)range) return 0;
167 switch((char *)dest - (char *)tm) {
168 case offsetof(struct tm, tm_yday):
175 else if (*s == '-') neg=1, s++;
176 if (!isdigit(*s)) return 0;
177 for (*dest=i=0; i<w && isdigit(*s); i++)
178 *dest = *dest * 10 + *s++ - '0';
179 if (neg) *dest = -*dest;
183 for (i=2*range-1; i>=0; i--) {
184 ex = nl_langinfo(min+i);
186 if (strncasecmp(s, ex, len)) continue;
199 if (want_century & 2) tm->tm_year += century * 100 - 1900;
200 else if (tm->tm_year <= 68) tm->tm_year += 100;