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, relyear = 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)) {
100 ex = nl_langinfo(PM_STR);
102 if (!strncasecmp(s, ex, len)) {
110 s = strptime(s, nl_langinfo(T_FMT_AMPM), tm);
114 s = strptime(s, "%H:%M", tm);
123 s = strptime(s, "%H:%M:%S", tm);
128 /* Throw away result, for now. (FIXME?) */
139 s = strptime(s, nl_langinfo(D_FMT), tm);
143 s = strptime(s, nl_langinfo(T_FMT), tm);
158 if (*s++ != '%') return 0;
163 if (!isdigit(*s)) return 0;
165 for (i=1; i<=min+range && isdigit(*s); i*=10)
166 *dest = *dest * 10 + *s++ - '0';
167 if (*dest - min >= (unsigned)range) return 0;
169 switch((char *)dest - (char *)tm) {
170 case offsetof(struct tm, tm_yday):
177 else if (*s == '-') neg=1, s++;
178 if (!isdigit(*s)) return 0;
179 for (*dest=i=0; i<w && isdigit(*s); i++)
180 *dest = *dest * 10 + *s++ - '0';
181 if (neg) *dest = -*dest;
185 for (i=2*range-1; i>=0; i--) {
186 ex = nl_langinfo(min+i);
188 if (strncasecmp(s, ex, len)) continue;
201 tm->tm_year = relyear;
202 if (want_century & 2) tm->tm_year += century * 100 - 1900;
203 else if (tm->tm_year <= 68) tm->tm_year += 100;