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;
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
);
54 s
= strptime(s
, "%m/%d/%y", tm
);
84 for (; *s
&& isspace(*s
); s
++);
87 ex
= nl_langinfo(AM_STR
);
89 if (!strncasecmp(s
, ex
, len
)) {
93 ex
= nl_langinfo(PM_STR
);
95 if (!strncasecmp(s
, ex
, len
)) {
102 s
= strptime(s
, nl_langinfo(T_FMT_AMPM
), tm
);
106 s
= strptime(s
, "%H:%M", tm
);
115 s
= strptime(s
, "%H:%M:%S", tm
);
120 /* Throw away result, for now. (FIXME?) */
131 s
= strptime(s
, nl_langinfo(D_FMT
), tm
);
135 s
= strptime(s
, nl_langinfo(T_FMT
), tm
);
150 if (*s
++ != '%') return 0;
155 if (!isdigit(*s
)) return 0;
157 for (i
=1; i
<=min
+range
&& isdigit(*s
); i
*=10)
158 *dest
= *dest
* 10 + *s
++ - '0';
159 if (*dest
- min
>= (unsigned)range
) return 0;
161 switch((char *)dest
- (char *)tm
) {
162 case offsetof(struct tm
, tm_yday
):
169 else if (*s
== '-') neg
=1, s
++;
170 if (!isdigit(*s
)) return 0;
171 for (*dest
=i
=0; i
<w
&& isdigit(*s
); i
++)
172 *dest
= *dest
* 10 + *s
++ - '0';
173 if (neg
) *dest
= -*dest
;
177 for (i
=2*range
-1; i
>=0; i
--) {
178 ex
= nl_langinfo(min
+i
);
180 if (strncasecmp(s
, ex
, len
)) continue;
193 if (want_century
& 2) tm
->tm_year
+= century
* 100 - 1900;
194 else if (tm
->tm_year
<= 68) tm
->tm_year
+= 100;