summaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-08-27 22:57:05 +0000
committerRoland McGrath <roland@gnu.org>2002-08-27 22:57:05 +0000
commit60f20c19fb3f4fc7c4d383dcfb2b54e70906e818 (patch)
tree5c50a3dad7d4aeb56445f638665bbfb73ec24f6a /time
parentc4d6f155e0ad6c3794fd3e7d2fa28e18ee9410b9 (diff)
downloadglibc-60f20c19fb3f4fc7c4d383dcfb2b54e70906e818.tar.gz
* 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/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.
Diffstat (limited to 'time')
-rw-r--r--time/Makefile2
-rw-r--r--time/strftime.c30
-rw-r--r--time/strptime.c42
-rw-r--r--time/strptime_l.c22
4 files changed, 86 insertions, 10 deletions
diff --git a/time/Makefile b/time/Makefile
index 5e55e3539f..246b9803fa 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -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
diff --git a/time/strftime.c b/time/strftime.c
index 5ed47f6cbd..8ae5985537 100644
--- a/time/strftime.c
+++ b/time/strftime.c
@@ -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)
@@ -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
@@ -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)
diff --git a/time/strptime.c b/time/strptime.c
index f127905102..bbd9e64550 100644
--- a/time/strptime.c
+++ b/time/strptime.c
@@ -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
@@ -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 };
@@ -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;
@@ -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;
@@ -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
diff --git a/time/strptime_l.c b/time/strptime_l.c
new file mode 100644
index 0000000000..681386003d
--- /dev/null
+++ b/time/strptime_l.c
@@ -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)