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);
89 for (; *s && isspace(*s); s++);
92 ex = nl_langinfo(AM_STR);
94 if (!strncasecmp(s, ex, len)) {
98 ex = nl_langinfo(PM_STR);
100 if (!strncasecmp(s, ex, len)) {
107 s = strptime(s, nl_langinfo(T_FMT_AMPM), tm);
111 s = strptime(s, "%H:%M", tm);
120 s = strptime(s, "%H:%M:%S", tm);
125 /* Throw away result, for now. (FIXME?) */
136 s = strptime(s, nl_langinfo(D_FMT), tm);
140 s = strptime(s, nl_langinfo(T_FMT), tm);
155 if (*s++ != '%') return 0;
160 if (!isdigit(*s)) return 0;
162 for (i=1; i<=min+range && isdigit(*s); i*=10)
163 *dest = *dest * 10 + *s++ - '0';
164 if (*dest - min >= (unsigned)range) return 0;
166 switch((char *)dest - (char *)tm) {
167 case offsetof(struct tm, tm_yday):
174 else if (*s == '-') neg=1, s++;
175 if (!isdigit(*s)) return 0;
176 for (*dest=i=0; i<w && isdigit(*s); i++)
177 *dest = *dest * 10 + *s++ - '0';
178 if (neg) *dest = -*dest;
182 for (i=2*range-1; i>=0; i--) {
183 ex = nl_langinfo(min+i);
185 if (strncasecmp(s, ex, len)) continue;
198 if (want_century & 2) tm->tm_year += century * 100 - 1900;
199 else if (tm->tm_year <= 68) tm->tm_year += 100;