Module Name: src
Committed By: joerg
Date: Sun Apr 21 17:45:47 UTC 2013
Modified Files:
src/include: time.h
src/lib/libc/include: namespace.h
src/lib/libc/locale: _def_time.c c_locale.c global_locale.c
nb_lc_time_misc.h
src/lib/libc/time: strftime.c strptime.c
Log Message:
Store time-specific locale data directly in the locale.
Ad dstrftime_l, strftime_lz and strptime_l.
To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/include/time.h
cvs rdiff -u -r1.164 -r1.165 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/locale/_def_time.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/locale/c_locale.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/locale/global_locale.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/nb_lc_time_misc.h
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/time/strftime.c
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/time/strptime.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/include/time.h
diff -u src/include/time.h:1.41 src/include/time.h:1.42
--- src/include/time.h:1.41 Tue Oct 2 01:42:06 2012
+++ src/include/time.h Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: time.h,v 1.41 2012/10/02 01:42:06 christos Exp $ */
+/* $NetBSD: time.h,v 1.42 2013/04/21 17:45:46 joerg Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -204,6 +204,21 @@ size_t strftime_z(const timezone_t, char
const char * __restrict, const struct tm * __restrict)
__attribute__((__format__(__strftime__, 4, 0)));
+#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
+# ifndef __LOCALE_T_DECLARED
+typedef struct _locale *locale_t;
+# define __LOCALE_T_DECLARED
+# endif
+size_t strftime_l(char * __restrict, size_t, const char * __restrict,
+ const struct tm * __restrict, locale_t)
+ __attribute__((__format__(__strftime__, 3, 0)));
+size_t strftime_lz(const timezone_t, char * __restrict, size_t,
+ const char * __restrict, const struct tm * __restrict, locale_t)
+ __attribute__((__format__(__strftime__, 4, 0)));
+char *strptime_l(const char * __restrict, const char * __restrict,
+ struct tm * __restrict, locale_t);
+#endif
+
#endif /* _NETBSD_SOURCE */
__END_DECLS
Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.164 src/lib/libc/include/namespace.h:1.165
--- src/lib/libc/include/namespace.h:1.164 Fri Apr 19 23:32:16 2013
+++ src/lib/libc/include/namespace.h Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.164 2013/04/19 23:32:16 joerg Exp $ */
+/* $NetBSD: namespace.h,v 1.165 2013/04/21 17:45:46 joerg Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -613,10 +613,13 @@
#define strcoll_l _strcoll_l
#define strdup _strdup
#define stresep _stresep
+#define strftime_l _strftime_l
+#define strftime_lz _strftime_lz
#define strftime_z _strftime_z
#define strndup _strndup
#define strncasecmp _strncasecmp
#define strptime _strptime
+#define strptime_l _strptime_l
#define strsep _strsep
#define strsignal _strsignal
#define strsuftoll _strsuftoll
Index: src/lib/libc/locale/_def_time.c
diff -u src/lib/libc/locale/_def_time.c:1.10 src/lib/libc/locale/_def_time.c:1.11
--- src/lib/libc/locale/_def_time.c:1.10 Sat May 17 03:49:54 2008
+++ src/lib/libc/locale/_def_time.c Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: _def_time.c,v 1.10 2008/05/17 03:49:54 ginsbach Exp $ */
+/* $NetBSD: _def_time.c,v 1.11 2013/04/21 17:45:46 joerg Exp $ */
/*
* Written by J.T. Conklin <[email protected]>.
@@ -7,7 +7,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _def_time.c,v 1.10 2008/05/17 03:49:54 ginsbach Exp $");
+__RCSID("$NetBSD: _def_time.c,v 1.11 2013/04/21 17:45:46 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
@@ -38,5 +38,3 @@ const _TimeLocale _DefaultTimeLocale =
"%H:%M:%S",
"%I:%M:%S %p"
};
-
-const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;
Index: src/lib/libc/locale/c_locale.c
diff -u src/lib/libc/locale/c_locale.c:1.1 src/lib/libc/locale/c_locale.c:1.2
--- src/lib/libc/locale/c_locale.c:1.1 Sun Apr 14 23:44:54 2013
+++ src/lib/libc/locale/c_locale.c Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: c_locale.c,v 1.1 2013/04/14 23:44:54 joerg Exp $ */
+/* $NetBSD: c_locale.c,v 1.2 2013/04/21 17:45:46 joerg Exp $ */
/*-
* Copyright (c)2008 Citrus Project,
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: c_locale.c,v 1.1 2013/04/14 23:44:54 joerg Exp $");
+__RCSID("$NetBSD: c_locale.c,v 1.2 2013/04/21 17:45:46 joerg Exp $");
#include <sys/types.h>
#include <sys/ctype_bits.h>
@@ -168,6 +168,8 @@ static const struct _locale __C_locale =
__UNCONST(&_DefaultNumericLocale),
[(size_t)LC_MESSAGES] = (_locale_part_t)
__UNCONST(&_DefaultMessagesLocale),
+ [(size_t)LC_TIME] = (_locale_part_t)
+ __UNCONST(&_DefaultTimeLocale),
},
};
Index: src/lib/libc/locale/global_locale.c
diff -u src/lib/libc/locale/global_locale.c:1.15 src/lib/libc/locale/global_locale.c:1.16
--- src/lib/libc/locale/global_locale.c:1.15 Sun Apr 14 23:30:16 2013
+++ src/lib/libc/locale/global_locale.c Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: global_locale.c,v 1.15 2013/04/14 23:30:16 joerg Exp $ */
+/* $NetBSD: global_locale.c,v 1.16 2013/04/21 17:45:46 joerg Exp $ */
/*-
* Copyright (c)2008 Citrus Project,
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: global_locale.c,v 1.15 2013/04/14 23:30:16 joerg Exp $");
+__RCSID("$NetBSD: global_locale.c,v 1.16 2013/04/21 17:45:46 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -170,5 +170,7 @@ struct _locale _global_locale = {
__UNCONST(&_DefaultNumericLocale),
[(size_t)LC_MESSAGES] = (_locale_part_t)
__UNCONST(&_DefaultMessagesLocale),
+ [(size_t)LC_TIME] = (_locale_part_t)
+ __UNCONST(&_DefaultTimeLocale),
},
};
Index: src/lib/libc/locale/nb_lc_time_misc.h
diff -u src/lib/libc/locale/nb_lc_time_misc.h:1.3 src/lib/libc/locale/nb_lc_time_misc.h:1.4
--- src/lib/libc/locale/nb_lc_time_misc.h:1.3 Sat Mar 27 15:25:22 2010
+++ src/lib/libc/locale/nb_lc_time_misc.h Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: nb_lc_time_misc.h,v 1.3 2010/03/27 15:25:22 tnozaki Exp $ */
+/* $NetBSD: nb_lc_time_misc.h,v 1.4 2013/04/21 17:45:46 joerg Exp $ */
/*-
* Copyright (c)2008 Citrus Project,
@@ -78,8 +78,6 @@ static __inline void
_PREFIX(fixup)(_TimeLocale *data)
{
_DIAGASSERT(data != NULL);
-
- _CurrentTimeLocale = data;
}
/*
Index: src/lib/libc/time/strftime.c
diff -u src/lib/libc/time/strftime.c:1.24 src/lib/libc/time/strftime.c:1.25
--- src/lib/libc/time/strftime.c:1.24 Sat Mar 2 21:24:28 2013
+++ src/lib/libc/time/strftime.c Sun Apr 21 17:45:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: strftime.c,v 1.24 2013/03/02 21:24:28 christos Exp $ */
+/* $NetBSD: strftime.c,v 1.25 2013/04/21 17:45:46 joerg Exp $ */
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
@@ -6,12 +6,16 @@
static char elsieid[] = "@(#)strftime.c 7.64";
static char elsieid[] = "@(#)strftime.c 8.3";
#else
-__RCSID("$NetBSD: strftime.c,v 1.24 2013/03/02 21:24:28 christos Exp $");
+__RCSID("$NetBSD: strftime.c,v 1.25 2013/04/21 17:45:46 joerg Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
+#include <stddef.h>
+#include <locale.h>
+#include "setlocale_local.h"
+
/*
** Based on the UCB version with the copyright notice and sccsid
** appearing below.
@@ -76,17 +80,20 @@ static const char sccsid[] = "@(#)strfti
#include "locale.h"
#ifdef __weak_alias
+__weak_alias(strftime_l, _strftime_l)
+__weak_alias(strftime_lz, _strftime_lz)
__weak_alias(strftime_z, _strftime_z)
#endif
#include "sys/localedef.h"
-#define Locale _CurrentTimeLocale
+#define _TIME_LOCALE(loc) \
+ ((_TimeLocale *)((loc)->part_impl[(size_t)LC_TIME]))
#define c_fmt d_t_fmt
static char * _add(const char *, char *, const char *);
static char * _conv(int, const char *, char *, const char *);
static char * _fmt(const timezone_t, const char *, const struct tm *, char *,
- const char *, int *);
+ const char *, int *, locale_t);
static char * _yconv(int, int, int, int, char *, const char *);
extern char * tzname[];
@@ -101,15 +108,25 @@ extern char * tzname[];
#define IN_ALL 3
size_t
-strftime_z(const timezone_t sp, char *const s, const size_t maxsize,
- const char *const format, const struct tm *const t)
+strftime_z(const timezone_t sp, char * __restrict s, size_t maxsize,
+ const char * __restrict format, const struct tm * __restrict t)
+{
+ return strftime_lz(sp, s, maxsize, format, t, *_current_locale());
+}
+
+size_t
+strftime_lz(const timezone_t sp, char *const s, const size_t maxsize,
+ const char *const format, const struct tm *const t, locale_t loc)
{
char * p;
int warn;
+ if (loc == NULL)
+ loc = _C_locale;
+
warn = IN_NONE;
p = _fmt(sp, ((format == NULL) ? "%c" : format), t, s, s + maxsize,
- &warn);
+ &warn, loc);
#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
(void) fprintf(stderr, "\n");
@@ -134,7 +151,7 @@ strftime_z(const timezone_t sp, char *co
static char *
_fmt(const timezone_t sp, const char *format, const struct tm *const t,
- char *pt, const char *const ptlim, int *warnp)
+ char *pt, const char *const ptlim, int *warnp, locale_t loc)
{
for ( ; *format; ++format) {
if (*format == '%') {
@@ -146,26 +163,26 @@ label:
case 'A':
pt = _add((t->tm_wday < 0 ||
t->tm_wday >= DAYSPERWEEK) ?
- "?" : Locale->day[t->tm_wday],
+ "?" : _TIME_LOCALE(loc)->day[t->tm_wday],
pt, ptlim);
continue;
case 'a':
pt = _add((t->tm_wday < 0 ||
t->tm_wday >= DAYSPERWEEK) ?
- "?" : Locale->abday[t->tm_wday],
+ "?" : _TIME_LOCALE(loc)->abday[t->tm_wday],
pt, ptlim);
continue;
case 'B':
pt = _add((t->tm_mon < 0 ||
t->tm_mon >= MONSPERYEAR) ?
- "?" : Locale->mon[t->tm_mon],
+ "?" : _TIME_LOCALE(loc)->mon[t->tm_mon],
pt, ptlim);
continue;
case 'b':
case 'h':
pt = _add((t->tm_mon < 0 ||
t->tm_mon >= MONSPERYEAR) ?
- "?" : Locale->abmon[t->tm_mon],
+ "?" : _TIME_LOCALE(loc)->abmon[t->tm_mon],
pt, ptlim);
continue;
case 'C':
@@ -183,7 +200,8 @@ label:
{
int warn2 = IN_SOME;
- pt = _fmt(sp, Locale->c_fmt, t, pt, ptlim, &warn2);
+ pt = _fmt(sp, _TIME_LOCALE(loc)->c_fmt, t, pt,
+ ptlim, &warn2, loc);
if (warn2 == IN_ALL)
warn2 = IN_THIS;
if (warn2 > *warnp)
@@ -191,7 +209,8 @@ label:
}
continue;
case 'D':
- pt = _fmt(sp, "%m/%d/%y", t, pt, ptlim, warnp);
+ pt = _fmt(sp, "%m/%d/%y", t, pt, ptlim, warnp,
+ loc);
continue;
case 'd':
pt = _conv(t->tm_mday, "%02d", pt, ptlim);
@@ -212,7 +231,8 @@ label:
pt = _conv(t->tm_mday, "%2d", pt, ptlim);
continue;
case 'F':
- pt = _fmt(sp, "%Y-%m-%d", t, pt, ptlim, warnp);
+ pt = _fmt(sp, "%Y-%m-%d", t, pt, ptlim, warnp,
+ loc);
continue;
case 'H':
pt = _conv(t->tm_hour, "%02d", pt, ptlim);
@@ -271,16 +291,17 @@ label:
continue;
case 'p':
pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
- Locale->am_pm[1] :
- Locale->am_pm[0],
+ _TIME_LOCALE(loc)->am_pm[1] :
+ _TIME_LOCALE(loc)->am_pm[0],
pt, ptlim);
continue;
case 'R':
- pt = _fmt(sp, "%H:%M", t, pt, ptlim, warnp);
+ pt = _fmt(sp, "%H:%M", t, pt, ptlim, warnp,
+ loc);
continue;
case 'r':
- pt = _fmt(sp, Locale->t_fmt_ampm, t, pt, ptlim,
- warnp);
+ pt = _fmt(sp, _TIME_LOCALE(loc)->t_fmt_ampm, t,
+ pt, ptlim, warnp, loc);
continue;
case 'S':
pt = _conv(t->tm_sec, "%02d", pt, ptlim);
@@ -305,7 +326,8 @@ label:
}
continue;
case 'T':
- pt = _fmt(sp, "%H:%M:%S", t, pt, ptlim, warnp);
+ pt = _fmt(sp, "%H:%M:%S", t, pt, ptlim, warnp,
+ loc);
continue;
case 't':
pt = _add("\t", pt, ptlim);
@@ -420,7 +442,8 @@ label:
** "date as dd-bbb-YYYY"
** (ado, 1993-05-24)
*/
- pt = _fmt(sp, "%e-%b-%Y", t, pt, ptlim, warnp);
+ pt = _fmt(sp, "%e-%b-%Y", t, pt, ptlim, warnp,
+ loc);
continue;
case 'W':
pt = _conv((t->tm_yday + DAYSPERWEEK -
@@ -433,13 +456,15 @@ label:
pt = _conv(t->tm_wday, "%d", pt, ptlim);
continue;
case 'X':
- pt = _fmt(sp, Locale->t_fmt, t, pt, ptlim, warnp);
+ pt = _fmt(sp, _TIME_LOCALE(loc)->t_fmt, t, pt,
+ ptlim, warnp, loc);
continue;
case 'x':
{
int warn2 = IN_SOME;
- pt = _fmt(sp, Locale->d_fmt, t, pt, ptlim, &warn2);
+ pt = _fmt(sp, _TIME_LOCALE(loc)->d_fmt, t, pt,
+ ptlim, &warn2, loc);
if (warn2 == IN_ALL)
warn2 = IN_THIS;
if (warn2 > *warnp)
@@ -557,8 +582,8 @@ label:
continue;
#if 0
case '+':
- pt = _fmt(sp, Locale->date_fmt, t, pt, ptlim,
- warnp);
+ pt = _fmt(sp, _TIME_LOCALE(loc)->date_fmt, t,
+ pt, ptlim, warnp, loc);
continue;
#endif
case '%':
@@ -586,6 +611,14 @@ strftime(char * const s, const size_t ma
return strftime_z(NULL, s, maxsize, format, t);
}
+size_t
+strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format,
+ const struct tm * __restrict t, locale_t loc)
+{
+ tzset();
+ return strftime_lz(NULL, s, maxsize, format, t, loc);
+}
+
static char *
_conv(const int n, const char *const format, char *const pt,
const char *const ptlim)
Index: src/lib/libc/time/strptime.c
diff -u src/lib/libc/time/strptime.c:1.36 src/lib/libc/time/strptime.c:1.37
--- src/lib/libc/time/strptime.c:1.36 Tue Mar 13 21:13:48 2012
+++ src/lib/libc/time/strptime.c Sun Apr 21 17:45:47 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: strptime.c,v 1.36 2012/03/13 21:13:48 christos Exp $ */
+/* $NetBSD: strptime.c,v 1.37 2013/04/21 17:45:47 joerg Exp $ */
/*-
* Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.36 2012/03/13 21:13:48 christos Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.37 2013/04/21 17:45:47 joerg Exp $");
#endif
#include "namespace.h"
@@ -42,12 +42,15 @@ __RCSID("$NetBSD: strptime.c,v 1.36 2012
#include <time.h>
#include <tzfile.h>
#include "private.h"
+#include "setlocale_local.h"
#ifdef __weak_alias
__weak_alias(strptime,_strptime)
+__weak_alias(strptime_l, _strptime_l)
#endif
-#define _ctloc(x) (_CurrentTimeLocale->x)
+#define _TIME_LOCALE(loc) \
+ ((_TimeLocale *)((loc)->part_impl[(size_t)LC_TIME]))
/*
* We do not implement alternate representations. However, we always
@@ -71,15 +74,23 @@ static const u_char *conv_num(const unsi
static const u_char *find_string(const u_char *, int *, const char * const *,
const char * const *, int);
-
char *
strptime(const char *buf, const char *fmt, struct tm *tm)
{
+ return strptime_l(buf, fmt, tm, *_current_locale());
+}
+
+char *
+strptime_l(const char *buf, const char *fmt, struct tm *tm, locale_t loc)
+{
unsigned char c;
const unsigned char *bp, *ep;
int alt_format, i, split_year = 0, neg = 0, offs;
const char *new_fmt;
+ if (loc == NULL)
+ loc = _C_locale;
+
bp = (const u_char *)buf;
while (bp != NULL && (c = *fmt++) != '\0') {
@@ -124,7 +135,7 @@ literal:
* "Complex" conversion rules, implemented through recursion.
*/
case 'c': /* Date and time, using the locale's format. */
- new_fmt = _ctloc(d_t_fmt);
+ new_fmt = _TIME_LOCALE(loc)->d_t_fmt;
goto recurse;
case 'D': /* The date as "%m/%d/%y". */
@@ -143,7 +154,7 @@ literal:
goto recurse;
case 'r': /* The time in 12-hour clock representation. */
- new_fmt =_ctloc(t_fmt_ampm);
+ new_fmt = _TIME_LOCALE(loc)->t_fmt_ampm;
LEGAL_ALT(0);
goto recurse;
@@ -153,11 +164,11 @@ literal:
goto recurse;
case 'X': /* The time, using the locale's format. */
- new_fmt =_ctloc(t_fmt);
+ new_fmt = _TIME_LOCALE(loc)->t_fmt;
goto recurse;
case 'x': /* The date, using the locale's format. */
- new_fmt =_ctloc(d_fmt);
+ new_fmt = _TIME_LOCALE(loc)->d_fmt;
recurse:
bp = (const u_char *)strptime((const char *)bp,
new_fmt, tm);
@@ -169,16 +180,17 @@ literal:
*/
case 'A': /* The day of week, using the locale's form. */
case 'a':
- bp = find_string(bp, &tm->tm_wday, _ctloc(day),
- _ctloc(abday), 7);
+ bp = find_string(bp, &tm->tm_wday,
+ _TIME_LOCALE(loc)->day, _TIME_LOCALE(loc)->abday, 7);
LEGAL_ALT(0);
continue;
case 'B': /* The month, using the locale's form. */
case 'b':
case 'h':
- bp = find_string(bp, &tm->tm_mon, _ctloc(mon),
- _ctloc(abmon), 12);
+ bp = find_string(bp, &tm->tm_mon,
+ _TIME_LOCALE(loc)->mon, _TIME_LOCALE(loc)->abmon,
+ 12);
LEGAL_ALT(0);
continue;
@@ -238,7 +250,8 @@ literal:
continue;
case 'p': /* The locale's equivalent of AM/PM. */
- bp = find_string(bp, &i, _ctloc(am_pm), NULL, 2);
+ bp = find_string(bp, &i, _TIME_LOCALE(loc)->am_pm,
+ NULL, 2);
if (tm->tm_hour > 11)
return NULL;
tm->tm_hour += i * 12;