1 --- strptime.c.orig 2004-11-25 11:38:45.000000000 -0800
2 +++ strptime.c 2005-02-24 01:09:32.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $");
7 +#include "xlocale_private.h"
13 #include "libc_private.h"
14 #include "timelocal.h"
16 -static char * _strptime(const char *, const char *, struct tm *, int *);
17 +static char * _strptime(const char *, const char *, struct tm *, int *, locale_t);
19 #define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
22 -_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp)
23 +_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, locale_t loc)
29 int Ealternative, Oalternative;
30 - struct lc_time_T *tptr = __get_current_time_locale();
31 + struct lc_time_T *tptr = __get_current_time_locale(loc);
39 - if (isspace((unsigned char)c))
40 - while (*buf != 0 && isspace((unsigned char)*buf))
41 + if (isspace_l((unsigned char)c, loc))
42 + while (*buf != 0 && isspace_l((unsigned char)*buf, loc))
50 - buf = _strptime(buf, tptr->date_fmt, tm, GMTp);
51 + buf = _strptime(buf, tptr->date_fmt, tm, GMTp, loc);
57 - if (!isdigit((unsigned char)*buf))
58 + if (!isdigit_l((unsigned char)*buf, loc))
61 /* XXX This will break for 3-digit centuries. */
63 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
64 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
72 - buf = _strptime(buf, tptr->c_fmt, tm, GMTp);
73 + buf = _strptime(buf, tptr->c_fmt, tm, GMTp, loc);
79 - buf = _strptime(buf, "%m/%d/%y", tm, GMTp);
80 + buf = _strptime(buf, "%m/%d/%y", tm, GMTp, loc);
88 - buf = _strptime(buf, "%Y-%m-%d", tm, GMTp);
89 + buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, loc);
95 - buf = _strptime(buf, "%H:%M", tm, GMTp);
96 + buf = _strptime(buf, "%H:%M", tm, GMTp, loc);
102 - buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp);
103 + buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp, loc);
109 - buf = _strptime(buf, "%H:%M:%S", tm, GMTp);
110 + buf = _strptime(buf, "%H:%M:%S", tm, GMTp, loc);
116 - buf = _strptime(buf, tptr->X_fmt, tm, GMTp);
117 + buf = _strptime(buf, tptr->X_fmt, tm, GMTp, loc);
123 - buf = _strptime(buf, tptr->x_fmt, tm, GMTp);
124 + buf = _strptime(buf, tptr->x_fmt, tm, GMTp, loc);
130 - if (!isdigit((unsigned char)*buf))
131 + if (!isdigit_l((unsigned char)*buf, loc))
135 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
136 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
140 @@ -214,14 +216,14 @@
144 - if (*buf == 0 || isspace((unsigned char)*buf))
145 + if (*buf == 0 || isspace_l((unsigned char)*buf, loc))
148 - if (!isdigit((unsigned char)*buf))
149 + if (!isdigit_l((unsigned char)*buf, loc))
153 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
154 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
162 - if (*buf != 0 && isspace((unsigned char)*buf))
163 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
164 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
165 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
169 @@ -254,11 +256,11 @@
170 * XXX The %l specifier may gobble one too many
171 * digits if used incorrectly.
173 - if (!isdigit((unsigned char)*buf))
174 + if (!isdigit_l((unsigned char)*buf, loc))
178 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
179 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
187 - if (*buf != 0 && isspace((unsigned char)*buf))
188 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
189 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
190 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
197 len = strlen(tptr->am);
198 - if (strncasecmp(buf, tptr->am, len) == 0) {
199 + if (strncasecmp_l(buf, tptr->am, len, loc) == 0) {
200 if (tm->tm_hour > 12)
202 if (tm->tm_hour == 12)
206 len = strlen(tptr->pm);
207 - if (strncasecmp(buf, tptr->pm, len) == 0) {
208 + if (strncasecmp_l(buf, tptr->pm, len, loc) == 0) {
209 if (tm->tm_hour > 12)
211 if (tm->tm_hour != 12)
212 @@ -307,12 +309,12 @@
214 for (i = 0; i < asizeof(tptr->weekday); i++) {
215 len = strlen(tptr->weekday[i]);
216 - if (strncasecmp(buf, tptr->weekday[i],
218 + if (strncasecmp_l(buf, tptr->weekday[i],
221 len = strlen(tptr->wday[i]);
222 - if (strncasecmp(buf, tptr->wday[i],
224 + if (strncasecmp_l(buf, tptr->wday[i],
228 if (i == asizeof(tptr->weekday))
229 @@ -330,11 +332,11 @@
230 * point to calculate a real value, so just check the
233 - if (!isdigit((unsigned char)*buf))
234 + if (!isdigit_l((unsigned char)*buf, loc))
238 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
239 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
243 @@ -342,13 +344,13 @@
247 - if (*buf != 0 && isspace((unsigned char)*buf))
248 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
249 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
250 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
255 - if (!isdigit((unsigned char)*buf))
256 + if (!isdigit_l((unsigned char)*buf, loc))
264 - if (*buf != 0 && isspace((unsigned char)*buf))
265 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
266 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
267 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
271 @@ -372,11 +374,11 @@
272 * XXX The %e specifier may gobble one too many
273 * digits if used incorrectly.
275 - if (!isdigit((unsigned char)*buf))
276 + if (!isdigit_l((unsigned char)*buf, loc))
280 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
281 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
289 - if (*buf != 0 && isspace((unsigned char)*buf))
290 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
291 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
292 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
296 @@ -398,19 +400,19 @@
299 len = strlen(tptr->alt_month[i]);
300 - if (strncasecmp(buf,
301 + if (strncasecmp_l(buf,
308 len = strlen(tptr->month[i]);
309 - if (strncasecmp(buf, tptr->month[i],
311 + if (strncasecmp_l(buf, tptr->month[i],
314 len = strlen(tptr->mon[i]);
315 - if (strncasecmp(buf, tptr->mon[i],
317 + if (strncasecmp_l(buf, tptr->mon[i],
322 @@ -422,11 +424,11 @@
326 - if (!isdigit((unsigned char)*buf))
327 + if (!isdigit_l((unsigned char)*buf, loc))
331 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
332 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
340 - if (*buf != 0 && isspace((unsigned char)*buf))
341 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
342 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
343 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
351 - n = strtol(buf, &cp, 10);
352 + n = strtol_l(buf, &cp, 10, loc);
353 if (errno == ERANGE || (long)(t = n) != n) {
356 @@ -464,14 +466,14 @@
360 - if (*buf == 0 || isspace((unsigned char)*buf))
361 + if (*buf == 0 || isspace_l((unsigned char)*buf, loc))
364 - if (!isdigit((unsigned char)*buf))
365 + if (!isdigit_l((unsigned char)*buf, loc))
368 len = (c == 'Y') ? 4 : 2;
369 - for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
370 + for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
378 - if (*buf != 0 && isspace((unsigned char)*buf))
379 - while (*ptr != 0 && !isspace((unsigned char)*ptr))
380 + if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
381 + while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
389 - for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/}
390 + for (cp = buf; *cp && isupper_l((unsigned char)*cp, loc); ++cp) {/*empty*/}
392 zonestr = alloca(cp - buf + 1);
393 strncpy(zonestr, buf, cp - buf);
398 - ret = _strptime(buf, fmt, tm, &gmt);
399 + ret = _strptime(buf, fmt, tm, &gmt, __current_locale());
401 + time_t t = timegm(tm);
402 + localtime_r(&t, tm);
409 +strptime_l(const char * __restrict buf, const char * __restrict fmt,
410 + struct tm * __restrict tm, locale_t loc)
415 + NORMALIZE_LOCALE(loc);
417 + ret = _strptime(buf, fmt, tm, &gmt, loc);
419 time_t t = timegm(tm);