Implement GNU extension strptime_l

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2016-08-23 17:42:47 +02:00
parent e636fe3d48
commit 0ecb846d2b
4 changed files with 94 additions and 66 deletions

View File

@ -92,6 +92,11 @@ char *_EXFUN(strptime, (const char *__restrict,
const char *__restrict, const char *__restrict,
struct tm *__restrict)); struct tm *__restrict));
#endif #endif
#if __GNU_VISIBLE
char *strptime_l (const char *__restrict, const char *__restrict,
struct tm *__restrict, locale_t);
#endif
#if __POSIX_VISIBLE #if __POSIX_VISIBLE
_VOID _EXFUN(tzset, (_VOID)); _VOID _EXFUN(tzset, (_VOID));
#endif #endif

View File

@ -30,6 +30,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#define _GNU_SOURCE
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
@ -68,14 +69,15 @@ is_leap_year (int year)
/* Needed for strptime. */ /* Needed for strptime. */
static int static int
match_string (const char *__restrict *buf, const char * const*strs) match_string (const char *__restrict *buf, const char * const*strs,
locale_t locale)
{ {
int i = 0; int i = 0;
for (i = 0; strs[i] != NULL; ++i) { for (i = 0; strs[i] != NULL; ++i) {
int len = strlen (strs[i]); int len = strlen (strs[i]);
if (strncasecmp (*buf, strs[i], len) == 0) { if (strncasecmp_l (*buf, strs[i], len, locale) == 0) {
*buf += len; *buf += len;
return i; return i;
} }
@ -148,25 +150,20 @@ set_week_number_mon4 (struct tm *timeptr, int wnum)
} }
} }
/* strptime: roken */
//extern "C"
char * char *
//strptime (const char *buf, const char *format, struct tm *timeptr) strptime_l (const char *buf, const char *format, struct tm *timeptr,
_DEFUN (strptime, (buf, format, timeptr), locale_t locale)
_CONST char *__restrict buf _AND
_CONST char *__restrict format _AND
struct tm *__restrict timeptr)
{ {
char c; char c;
int ymd = 0; int ymd = 0;
const struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale (); const struct lc_time_T *_CurrentTimeLocale = __get_time_locale (locale);
for (; (c = *format) != '\0'; ++format) { for (; (c = *format) != '\0'; ++format) {
char *s; char *s;
int ret; int ret;
if (isspace ((unsigned char) c)) { if (isspace_l ((unsigned char) c, locale)) {
while (isspace ((unsigned char) *buf)) while (isspace_l ((unsigned char) *buf, locale))
++buf; ++buf;
} else if (c == '%' && format[1] != '\0') { } else if (c == '%' && format[1] != '\0') {
c = *++format; c = *++format;
@ -174,21 +171,21 @@ _DEFUN (strptime, (buf, format, timeptr),
c = *++format; c = *++format;
switch (c) { switch (c) {
case 'A' : case 'A' :
ret = match_string (&buf, _ctloc (weekday)); ret = match_string (&buf, _ctloc (weekday), locale);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
timeptr->tm_wday = ret; timeptr->tm_wday = ret;
ymd |= SET_WDAY; ymd |= SET_WDAY;
break; break;
case 'a' : case 'a' :
ret = match_string (&buf, _ctloc (wday)); ret = match_string (&buf, _ctloc (wday), locale);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
timeptr->tm_wday = ret; timeptr->tm_wday = ret;
ymd |= SET_WDAY; ymd |= SET_WDAY;
break; break;
case 'B' : case 'B' :
ret = match_string (&buf, _ctloc (month)); ret = match_string (&buf, _ctloc (month), locale);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
timeptr->tm_mon = ret; timeptr->tm_mon = ret;
@ -196,14 +193,14 @@ _DEFUN (strptime, (buf, format, timeptr),
break; break;
case 'b' : case 'b' :
case 'h' : case 'h' :
ret = match_string (&buf, _ctloc (mon)); ret = match_string (&buf, _ctloc (mon), locale);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
timeptr->tm_mon = ret; timeptr->tm_mon = ret;
ymd |= SET_MON; ymd |= SET_MON;
break; break;
case 'C' : case 'C' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_year = (ret * 100) - tm_year_base; timeptr->tm_year = (ret * 100) - tm_year_base;
@ -211,14 +208,14 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YEAR; ymd |= SET_YEAR;
break; break;
case 'c' : /* %a %b %e %H:%M:%S %Y */ case 'c' : /* %a %b %e %H:%M:%S %Y */
s = strptime (buf, _ctloc (c_fmt), timeptr); s = strptime_l (buf, _ctloc (c_fmt), timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
ymd |= SET_WDAY | SET_YMD; ymd |= SET_WDAY | SET_YMD;
break; break;
case 'D' : /* %m/%d/%y */ case 'D' : /* %m/%d/%y */
s = strptime (buf, "%m/%d/%y", timeptr); s = strptime_l (buf, "%m/%d/%y", timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
@ -226,7 +223,7 @@ _DEFUN (strptime, (buf, format, timeptr),
break; break;
case 'd' : case 'd' :
case 'e' : case 'e' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_mday = ret; timeptr->tm_mday = ret;
@ -235,7 +232,7 @@ _DEFUN (strptime, (buf, format, timeptr),
break; break;
case 'H' : case 'H' :
case 'k' : case 'k' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_hour = ret; timeptr->tm_hour = ret;
@ -243,7 +240,7 @@ _DEFUN (strptime, (buf, format, timeptr),
break; break;
case 'I' : case 'I' :
case 'l' : case 'l' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
if (ret == 12) if (ret == 12)
@ -253,7 +250,7 @@ _DEFUN (strptime, (buf, format, timeptr),
buf = s; buf = s;
break; break;
case 'j' : case 'j' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_yday = ret - 1; timeptr->tm_yday = ret - 1;
@ -261,7 +258,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YDAY; ymd |= SET_YDAY;
break; break;
case 'm' : case 'm' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_mon = ret - 1; timeptr->tm_mon = ret - 1;
@ -269,7 +266,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_MON; ymd |= SET_MON;
break; break;
case 'M' : case 'M' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_min = ret; timeptr->tm_min = ret;
@ -282,7 +279,7 @@ _DEFUN (strptime, (buf, format, timeptr),
return NULL; return NULL;
break; break;
case 'p' : case 'p' :
ret = match_string (&buf, _ctloc (am_pm)); ret = match_string (&buf, _ctloc (am_pm), locale);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
if (timeptr->tm_hour == 0) { if (timeptr->tm_hour == 0) {
@ -292,19 +289,19 @@ _DEFUN (strptime, (buf, format, timeptr),
timeptr->tm_hour += 12; timeptr->tm_hour += 12;
break; break;
case 'r' : /* %I:%M:%S %p */ case 'r' : /* %I:%M:%S %p */
s = strptime (buf, _ctloc (ampm_fmt), timeptr); s = strptime_l (buf, _ctloc (ampm_fmt), timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
break; break;
case 'R' : /* %H:%M */ case 'R' : /* %H:%M */
s = strptime (buf, "%H:%M", timeptr); s = strptime_l (buf, "%H:%M", timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
break; break;
case 'S' : case 'S' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_sec = ret; timeptr->tm_sec = ret;
@ -317,13 +314,13 @@ _DEFUN (strptime, (buf, format, timeptr),
return NULL; return NULL;
break; break;
case 'T' : /* %H:%M:%S */ case 'T' : /* %H:%M:%S */
s = strptime (buf, "%H:%M:%S", timeptr); s = strptime_l (buf, "%H:%M:%S", timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
break; break;
case 'u' : case 'u' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_wday = ret - 1; timeptr->tm_wday = ret - 1;
@ -331,7 +328,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_WDAY; ymd |= SET_WDAY;
break; break;
case 'w' : case 'w' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_wday = ret; timeptr->tm_wday = ret;
@ -339,7 +336,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_WDAY; ymd |= SET_WDAY;
break; break;
case 'U' : case 'U' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
set_week_number_sun (timeptr, ret); set_week_number_sun (timeptr, ret);
@ -347,7 +344,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YDAY; ymd |= SET_YDAY;
break; break;
case 'V' : case 'V' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
set_week_number_mon4 (timeptr, ret); set_week_number_mon4 (timeptr, ret);
@ -355,7 +352,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YDAY; ymd |= SET_YDAY;
break; break;
case 'W' : case 'W' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
set_week_number_mon (timeptr, ret); set_week_number_mon (timeptr, ret);
@ -363,20 +360,20 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YDAY; ymd |= SET_YDAY;
break; break;
case 'x' : case 'x' :
s = strptime (buf, _ctloc (x_fmt), timeptr); s = strptime_l (buf, _ctloc (x_fmt), timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
ymd |= SET_YMD; ymd |= SET_YMD;
break; break;
case 'X' : case 'X' :
s = strptime (buf, _ctloc (X_fmt), timeptr); s = strptime_l (buf, _ctloc (X_fmt), timeptr, locale);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
buf = s; buf = s;
break; break;
case 'y' : case 'y' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
if (ret < 70) if (ret < 70)
@ -387,7 +384,7 @@ _DEFUN (strptime, (buf, format, timeptr),
ymd |= SET_YEAR; ymd |= SET_YEAR;
break; break;
case 'Y' : case 'Y' :
ret = strtol (buf, &s, 10); ret = strtol_l (buf, &s, 10, locale);
if (s == buf) if (s == buf)
return NULL; return NULL;
timeptr->tm_year = ret - tm_year_base; timeptr->tm_year = ret - tm_year_base;
@ -475,3 +472,8 @@ _DEFUN (strptime, (buf, format, timeptr),
return (char *)buf; return (char *)buf;
} }
char *
strptime (const char *buf, const char *format, struct tm *timeptr)
{
return strptime_l (buf, format, timeptr, __get_current_locale ());
}

View File

@ -1364,6 +1364,7 @@ strndup SIGFE
strnlen NOSIGFE strnlen NOSIGFE
strpbrk NOSIGFE strpbrk NOSIGFE
strptime SIGFE strptime SIGFE
strptime_l SIGFE
strrchr NOSIGFE strrchr NOSIGFE
strsep NOSIGFE strsep NOSIGFE
strsignal SIGFE strsignal SIGFE

View File

@ -102,7 +102,7 @@ free_era_info (era_info_t *era_info)
} }
static era_info_t * static era_info_t *
get_era_info (const char *era) get_era_info (const char *era, locale_t locale)
{ {
char *c; char *c;
era_info_t *ei = NULL; era_info_t *ei = NULL;
@ -122,14 +122,14 @@ get_era_info (const char *era)
ei[cur].num = 1; ei[cur].num = 1;
ei[cur].dir = (*era == '+') ? 1 : -1; ei[cur].dir = (*era == '+') ? 1 : -1;
era += 2; era += 2;
ei[cur].offset = strtol (era, &c, 10); ei[cur].offset = strtol_l (era, &c, 10, locale);
era = c + 1; era = c + 1;
ei[cur].start.tm_year = strtol (era, &c, 10); ei[cur].start.tm_year = strtol_l (era, &c, 10, locale);
/* Adjust offset for negative gregorian dates. */ /* Adjust offset for negative gregorian dates. */
if (ei[cur].start.tm_year < 0) if (ei[cur].start.tm_year < 0)
++ei[cur].start.tm_year; ++ei[cur].start.tm_year;
ei[cur].start.tm_mon = strtol (c + 1, &c, 10); ei[cur].start.tm_mon = strtol_l (c + 1, &c, 10, locale);
ei[cur].start.tm_mday = strtol (c + 1, &c, 10); ei[cur].start.tm_mday = strtol_l (c + 1, &c, 10, locale);
ei[cur].start.tm_hour = ei[cur].start.tm_min = ei[cur].start.tm_sec = 0; ei[cur].start.tm_hour = ei[cur].start.tm_min = ei[cur].start.tm_sec = 0;
era = c + 1; era = c + 1;
if (era[0] == '-' && era[1] == '*') if (era[0] == '-' && era[1] == '*')
@ -151,12 +151,12 @@ get_era_info (const char *era)
} }
else else
{ {
ei[cur].end.tm_year = strtol (era, &c, 10); ei[cur].end.tm_year = strtol_l (era, &c, 10, locale);
/* Adjust offset for negative gregorian dates. */ /* Adjust offset for negative gregorian dates. */
if (ei[cur].end.tm_year < 0) if (ei[cur].end.tm_year < 0)
++ei[cur].end.tm_year; ++ei[cur].end.tm_year;
ei[cur].end.tm_mon = strtol (c + 1, &c, 10); ei[cur].end.tm_mon = strtol_l (c + 1, &c, 10, locale);
ei[cur].end.tm_mday = strtol (c + 1, &c, 10); ei[cur].end.tm_mday = strtol_l (c + 1, &c, 10, locale);
ei[cur].end.tm_mday = 31; ei[cur].end.tm_mday = 31;
ei[cur].end.tm_hour = 23; ei[cur].end.tm_hour = 23;
ei[cur].end.tm_min = ei[cur].end.tm_sec = 59; ei[cur].end.tm_min = ei[cur].end.tm_sec = 59;
@ -305,11 +305,13 @@ static const unsigned char *conv_num(const unsigned char *, int *, uint, uint,
alt_digits_t *); alt_digits_t *);
static const unsigned char *find_string(const unsigned char *, int *, static const unsigned char *find_string(const unsigned char *, int *,
const char * const *, const char * const *,
const char * const *, int); const char * const *, int,
locale_t);
static char * static char *
__strptime(const char *buf, const char *fmt, struct tm *tm, __strptime(const char *buf, const char *fmt, struct tm *tm,
era_info_t **era_info, alt_digits_t **alt_digits) era_info_t **era_info, alt_digits_t **alt_digits,
locale_t locale)
{ {
unsigned char c; unsigned char c;
const unsigned char *bp; const unsigned char *bp;
@ -323,8 +325,7 @@ __strptime(const char *buf, const char *fmt, struct tm *tm,
int ymd = 0; int ymd = 0;
bp = (const unsigned char *)buf; bp = (const unsigned char *)buf;
const struct lc_time_T *_CurrentTimeLocale = const struct lc_time_T *_CurrentTimeLocale = __get_time_locale (locale);
__get_current_time_locale ();
while (bp != NULL && (c = *fmt++) != '\0') { while (bp != NULL && (c = *fmt++) != '\0') {
/* Clear `alternate' modifier prior to new conversion. */ /* Clear `alternate' modifier prior to new conversion. */
@ -334,8 +335,8 @@ __strptime(const char *buf, const char *fmt, struct tm *tm,
i = 0; i = 0;
/* Eat up white-space. */ /* Eat up white-space. */
if (isspace(c)) { if (isspace_l(c, locale)) {
while (isspace(*bp)) while (isspace_l(*bp, locale))
bp++; bp++;
continue; continue;
} }
@ -360,7 +361,8 @@ literal:
LEGAL_ALT(0); LEGAL_ALT(0);
alt_format |= ALT_E; alt_format |= ALT_E;
if (!*era_info && *_CurrentTimeLocale->era) if (!*era_info && *_CurrentTimeLocale->era)
*era_info = get_era_info (_CurrentTimeLocale->era); *era_info = get_era_info (_CurrentTimeLocale->era,
locale);
goto again; goto again;
case 'O': /* "%O?" alternative conversion modifier. */ case 'O': /* "%O?" alternative conversion modifier. */
@ -385,7 +387,7 @@ literal:
LEGAL_ALT(0); LEGAL_ALT(0);
{ {
char *end; char *end;
width = strtoul (fmt - 1, &end, 10); width = strtoul_l (fmt - 1, &end, 10, locale);
fmt = (const char *) end; fmt = (const char *) end;
goto again; goto again;
} }
@ -410,7 +412,8 @@ literal:
LEGAL_ALT(0); LEGAL_ALT(0);
ymd |= SET_YMD; ymd |= SET_YMD;
char *tmp = __strptime ((const char *) bp, "%Y-%m-%d", char *tmp = __strptime ((const char *) bp, "%Y-%m-%d",
tm, era_info, alt_digits); tm, era_info, alt_digits,
locale);
if (tmp && (uint) (tmp - (char *) bp) > width) if (tmp && (uint) (tmp - (char *) bp) > width)
return NULL; return NULL;
bp = (const unsigned char *) tmp; bp = (const unsigned char *) tmp;
@ -446,7 +449,7 @@ literal:
recurse: recurse:
bp = (const unsigned char *) bp = (const unsigned char *)
__strptime((const char *)bp, new_fmt, tm, __strptime((const char *)bp, new_fmt, tm,
era_info, alt_digits); era_info, alt_digits, locale);
continue; continue;
/* /*
@ -455,7 +458,7 @@ literal:
case 'A': /* The day of week, using the locale's form. */ case 'A': /* The day of week, using the locale's form. */
case 'a': case 'a':
bp = find_string(bp, &tm->tm_wday, _ctloc(weekday), bp = find_string(bp, &tm->tm_wday, _ctloc(weekday),
_ctloc(wday), 7); _ctloc(wday), 7, locale);
LEGAL_ALT(0); LEGAL_ALT(0);
ymd |= SET_WDAY; ymd |= SET_WDAY;
continue; continue;
@ -464,7 +467,7 @@ literal:
case 'b': case 'b':
case 'h': case 'h':
bp = find_string(bp, &tm->tm_mon, _ctloc(month), bp = find_string(bp, &tm->tm_mon, _ctloc(month),
_ctloc(mon), 12); _ctloc(mon), 12, locale);
LEGAL_ALT(0); LEGAL_ALT(0);
ymd |= SET_WDAY; ymd |= SET_WDAY;
continue; continue;
@ -554,7 +557,8 @@ literal:
continue; continue;
case 'p': /* The locale's equivalent of AM/PM. */ case 'p': /* The locale's equivalent of AM/PM. */
bp = find_string(bp, &i, _ctloc(am_pm), NULL, 2); bp = find_string(bp, &i, _ctloc(am_pm), NULL, 2,
locale);
if (tm->tm_hour > 11) if (tm->tm_hour > 11)
return NULL; return NULL;
tm->tm_hour += i * 12; tm->tm_hour += i * 12;
@ -604,7 +608,7 @@ literal:
char *tmp = __strptime ((const char *) bp, char *tmp = __strptime ((const char *) bp,
tmp_ei->era_Y, tmp_ei->era_Y,
tm, &tmp_ei, tm, &tmp_ei,
alt_digits); alt_digits, locale);
if (tmp) if (tmp)
{ {
bp = (const unsigned char *) tmp; bp = (const unsigned char *) tmp;
@ -675,7 +679,7 @@ literal:
ep = find_string(bp, &i, ep = find_string(bp, &i,
(const char * const *)tzname, (const char * const *)tzname,
NULL, 2); NULL, 2, locale);
if (ep != NULL) { if (ep != NULL) {
tm->tm_isdst = i; tm->tm_isdst = i;
#ifdef TM_GMTOFF #ifdef TM_GMTOFF
@ -696,7 +700,7 @@ literal:
*/ */
case 'n': /* Any kind of white-space. */ case 'n': /* Any kind of white-space. */
case 't': case 't':
while (isspace(*bp)) while (isspace_l(*bp, locale))
bp++; bp++;
LEGAL_ALT(0); LEGAL_ALT(0);
continue; continue;
@ -775,13 +779,28 @@ literal:
return (char *) bp; return (char *) bp;
} }
char *
strptime_l (const char *__restrict buf, const char *__restrict fmt,
struct tm *__restrict tm, locale_t locale)
{
era_info_t *era_info = NULL;
alt_digits_t *alt_digits = NULL;
char *ret = __strptime (buf, fmt, tm, &era_info, &alt_digits, locale);
if (era_info)
free_era_info (era_info);
if (alt_digits)
free_alt_digits (alt_digits);
return ret;
}
char * char *
strptime (const char *__restrict buf, const char *__restrict fmt, strptime (const char *__restrict buf, const char *__restrict fmt,
struct tm *__restrict tm) struct tm *__restrict tm)
{ {
era_info_t *era_info = NULL; era_info_t *era_info = NULL;
alt_digits_t *alt_digits = NULL; alt_digits_t *alt_digits = NULL;
char *ret = __strptime (buf, fmt, tm, &era_info, &alt_digits); char *ret = __strptime (buf, fmt, tm, &era_info, &alt_digits,
__get_current_locale ());
if (era_info) if (era_info)
free_era_info (era_info); free_era_info (era_info);
if (alt_digits) if (alt_digits)
@ -824,7 +843,7 @@ conv_num(const unsigned char *buf, int *dest, uint llim, uint ulim,
static const unsigned char * static const unsigned char *
find_string(const unsigned char *bp, int *tgt, const char * const *n1, find_string(const unsigned char *bp, int *tgt, const char * const *n1,
const char * const *n2, int c) const char * const *n2, int c, locale_t locale)
{ {
int i; int i;
unsigned int len; unsigned int len;
@ -833,7 +852,8 @@ find_string(const unsigned char *bp, int *tgt, const char * const *n1,
for (; n1 != NULL; n1 = n2, n2 = NULL) { for (; n1 != NULL; n1 = n2, n2 = NULL) {
for (i = 0; i < c; i++, n1++) { for (i = 0; i < c; i++, n1++) {
len = strlen(*n1); len = strlen(*n1);
if (strncasecmp(*n1, (const char *)bp, len) == 0) { if (strncasecmp_l(*n1, (const char *)bp, len,
locale) == 0) {
*tgt = i; *tgt = i;
return bp + len; return bp + len;
} }