Skip to content

Commit

Permalink
* time/strptime.c [USE_IN_EXTENDED_LOCALE_MODEL]: Define __strptime_l
Browse files Browse the repository at this point in the history
	instead, taking an extra __locale_t argument.
	* time/Makefile (routines): Add strptime_l.
	* time/strptime_l.c: New file.
	* time/strftime.c [USE_IN_EXTENDED_LOCALE_MODEL]: Define __strftime_l
	or __wcsftime_l instead, taking an extra __locale_t argument.
  • Loading branch information
Roland McGrath committed Aug 27, 2002
1 parent c4d6f15 commit 60f20c1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
2002-08-27 Roland McGrath <roland@redhat.com>

* time/strptime.c [USE_IN_EXTENDED_LOCALE_MODEL]: Define __strptime_l
instead, taking an extra __locale_t argument.
* time/Makefile (routines): Add strptime_l.
* time/time.h (__strptime_l, strptime_l): Declare them.
* time/strptime_l.c: New file.

* time/time.h (__strftime_l, strftime_l): Declare them.
* wcsmbs/wchar.h (__wcsftime_l, wcsftime_l): Declare them.
Expand All @@ -9,6 +13,8 @@
* time/Makefile (routines): Add strftime_l, wcsftime_l.
* time/Versions (libc: GLIBC_2.3): Add __strftime_l, __wcsftime_l,
strftime_l, wcsftime_l.
* time/strftime.c [USE_IN_EXTENDED_LOCALE_MODEL]: Define __strftime_l
or __wcsftime_l instead, taking an extra __locale_t argument.

* locale/Versions (libc: GLIBC_PRIVATE): Move __uselocale to ...
(libc: GLIBC_2.3): ... here.
Expand Down
2 changes: 1 addition & 1 deletion time/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ routines := offtime asctime clock ctime ctime_r difftime \
gettimeofday settimeofday adjtime tzset \
tzfile getitimer setitimer \
stime dysize timegm ftime \
strptime getdate \
getdate strptime strptime_l \
strftime wcsftime strftime_l wcsftime_l
distribute := datemsk

Expand Down
30 changes: 27 additions & 3 deletions time/strftime.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ static const CHAR_T zeroes[16] = /* "0000000000000000" */
#endif


#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
/* We use this code also for the extended locale handling where the
function gets as an additional argument the locale which has to be
used. To access the values we have to redefine the _NL_CURRENT
macro. */
# define strftime __strftime_l
# define wcsftime __wcsftime_l
# undef _NL_CURRENT
# define _NL_CURRENT(category, item) \
(current->values[_NL_ITEM_INDEX (item)].string)
# define LOCALE_PARAM , loc
# define LOCALE_ARG , loc
# define LOCALE_PARAM_DECL __locale_t loc;
#else
# define LOCALE_PARAM
# define LOCALE_ARG
# define LOCALE_PARAM_DECL
#endif

#ifdef COMPILE_WIDE
# define TOUPPER(Ch) towupper (Ch)
# define TOLOWER(Ch) towlower (Ch)
Expand Down Expand Up @@ -466,13 +485,18 @@ static CHAR_T const month_name[][10] =
anywhere, so to determine how many characters would be
written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */
size_t
my_strftime (s, maxsize, format, tp ut_argument)
my_strftime (s, maxsize, format, tp ut_argument LOCALE_PARAM)
CHAR_T *s;
size_t maxsize;
const CHAR_T *format;
const struct tm *tp;
ut_argument_spec
LOCALE_PARAM_DECL
{
#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
const struct locale_data *const current = loc->__locales[LC_TIME];
#endif

int hour12 = tp->tm_hour;
#ifdef _NL_CURRENT
/* We cannot make the following values variables since we must delay
Expand Down Expand Up @@ -807,9 +831,9 @@ my_strftime (s, maxsize, format, tp ut_argument)
{
CHAR_T *old_start = p;
size_t len = my_strftime (NULL, (size_t) -1, subfmt,
tp ut_argument);
tp ut_argument LOCALE_ARG);
add (len, my_strftime (p, maxsize - i, subfmt,
tp ut_argument));
tp ut_argument LOCALE_ARG));

if (to_uppcase)
while (old_start < p)
Expand Down
42 changes: 36 additions & 6 deletions time/strptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ localtime_r (t, tp)
#endif
#define recursive(new_fmt) \
(*(new_fmt) != '\0' \
&& (rp = strptime_internal (rp, (new_fmt), tm, decided, era_cnt)) != NULL)
&& (rp = strptime_internal (rp, (new_fmt), tm, \
decided, era_cnt LOCALE_ARG)) != NULL)


#ifdef _LIBC
Expand Down Expand Up @@ -185,6 +186,27 @@ const unsigned short int __mon_yday[2][13] =
};
#endif

#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
/* We use this code also for the extended locale handling where the
function gets as an additional argument the locale which has to be
used. To access the values we have to redefine the _NL_CURRENT
macro. */
# define strptime __strptime_l
# undef _NL_CURRENT
# define _NL_CURRENT(category, item) \
(current->values[_NL_ITEM_INDEX (item)].string)
# define LOCALE_PARAM , locale
# define LOCALE_ARG , locale
# define LOCALE_PARAM_PROTO , __locale_t locale
# define LOCALE_PARAM_DECL __locale_t locale;
#else
# define LOCALE_PARAM
# define LOCALE_ARG
# define LOCALE_PARAM_DECL
# define LOCALE_PARAM_PROTO
#endif


/* Status of lookup: do we use the locale data or the raw data? */
enum locale_status { not, loc, raw };

Expand Down Expand Up @@ -222,24 +244,31 @@ day_of_the_year (struct tm *tm)
+ (tm->tm_mday - 1));
}


static char *
#ifdef _LIBC
internal_function
#endif
strptime_internal __P ((const char *rp, const char *fmt, struct tm *tm,
enum locale_status *decided, int era_cnt));
enum locale_status *decided, int era_cnt
LOCALE_PARAM_PROTO));

static char *
#ifdef _LIBC
internal_function
#endif
strptime_internal (rp, fmt, tm, decided, era_cnt)
strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
const char *rp;
const char *fmt;
struct tm *tm;
enum locale_status *decided;
int era_cnt;
LOCALE_PARAM_DECL
{
#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
const struct locale_data *const current = locale->__locales[LC_TIME];
#endif

const char *rp_backup;
int cnt;
size_t val;
Expand Down Expand Up @@ -1023,10 +1052,11 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)


char *
strptime (buf, format, tm)
strptime (buf, format, tm LOCALE_PARAM)
const char *buf;
const char *format;
struct tm *tm;
LOCALE_PARAM_DECL
{
enum locale_status decided;

Expand All @@ -1035,8 +1065,8 @@ strptime (buf, format, tm)
#else
decided = raw;
#endif
return strptime_internal (buf, format, tm, &decided, -1);
return strptime_internal (buf, format, tm, &decided, -1 LOCALE_ARG);
}
#ifdef _LIBC
#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
libc_hidden_def (strptime)
#endif
22 changes: 22 additions & 0 deletions time/strptime_l.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#define USE_IN_EXTENDED_LOCALE_MODEL 1
#include <strptime.c>

weak_alias (__strptime_l, strptime_l)

0 comments on commit 60f20c1

Please sign in to comment.