10 char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
12 int i, w, neg, adj, min, range, *dest;
17 if (isspace(*f)) for (; *s && isspace(*s); s++);
18 else if (*s != *f) return 0;
25 if (isdigit(*f)) w=strtoul(f, (void *)&f, 10);
34 case 'b': case 'B': case 'h':
40 s = strptime(s, nl_langinfo(D_T_FMT), tm);
50 s = strptime(s, "%m/%d/%y", tm);
80 for (; *s && isspace(*s); s++);
83 ex = nl_langinfo(AM_STR);
85 if (!strncasecmp(s, ex, len)) {
89 ex = nl_langinfo(PM_STR);
91 if (!strncasecmp(s, ex, len)) {
98 s = strptime(s, nl_langinfo(T_FMT_AMPM), tm);
102 s = strptime(s, "%H:%M", tm);
111 s = strptime(s, "%H:%M:%S", tm);
124 s = strptime(s, nl_langinfo(D_FMT), tm);
128 s = strptime(s, nl_langinfo(T_FMT), tm);
140 if (*s++ != '%') return 0;
143 if (!isdigit(*s)) return 0;
145 for (i=1; i<=min+range && isdigit(*s); i*=10)
146 *dest = *dest * 10 + *s++ - '0';
147 if (*dest - min >= (unsigned)range) return 0;
149 switch((char *)dest - (char *)tm) {
150 case offsetof(struct tm, tm_yday):
157 else if (*s == '-') neg=1, s++;
158 if (!isdigit(*s)) return 0;
159 for (*dest=i=0; i<w && isdigit(*s); i++)
160 *dest = *dest * 10 + *s++ - '0';
161 if (neg) *dest = -*dest;
165 for (i=2*range-1; i>=0; i--) {
166 ex = nl_langinfo(min+i);
168 if (strncasecmp(s, ex, len)) continue;