Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Store time-specific locale data directly in the locale.
details: https://anonhg.NetBSD.org/src/rev/4e4d88895ce5
branches: trunk
changeset: 786243:4e4d88895ce5
user: joerg <joerg%NetBSD.org@localhost>
date: Sun Apr 21 17:45:46 2013 +0000
description:
Store time-specific locale data directly in the locale.
Ad dstrftime_l, strftime_lz and strptime_l.
diffstat:
include/time.h | 17 +++++++-
lib/libc/include/namespace.h | 5 +-
lib/libc/locale/_def_time.c | 6 +-
lib/libc/locale/c_locale.c | 6 +-
lib/libc/locale/global_locale.c | 6 +-
lib/libc/locale/nb_lc_time_misc.h | 4 +-
lib/libc/time/strftime.c | 85 +++++++++++++++++++++++++++-----------
lib/libc/time/strptime.c | 39 +++++++++++-----
8 files changed, 116 insertions(+), 52 deletions(-)
diffs (truncated from 509 to 300 lines):
diff -r 1d5e653a213b -r 4e4d88895ce5 include/time.h
--- a/include/time.h Sun Apr 21 15:42:11 2013 +0000
+++ b/include/time.h Sun Apr 21 17:45:46 2013 +0000
@@ -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 @@
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
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/include/namespace.h Sun Apr 21 17:45:46 2013 +0000
@@ -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
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/locale/_def_time.c
--- a/lib/libc/locale/_def_time.c Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/locale/_def_time.c Sun Apr 21 17:45:46 2013 +0000
@@ -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 <jtc%NetBSD.org@localhost>.
@@ -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 @@
"%H:%M:%S",
"%I:%M:%S %p"
};
-
-const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/locale/c_locale.c
--- a/lib/libc/locale/c_locale.c Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/locale/c_locale.c Sun Apr 21 17:45:46 2013 +0000
@@ -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 @@
__UNCONST(&_DefaultNumericLocale),
[(size_t)LC_MESSAGES] = (_locale_part_t)
__UNCONST(&_DefaultMessagesLocale),
+ [(size_t)LC_TIME] = (_locale_part_t)
+ __UNCONST(&_DefaultTimeLocale),
},
};
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/locale/global_locale.c
--- a/lib/libc/locale/global_locale.c Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/locale/global_locale.c Sun Apr 21 17:45:46 2013 +0000
@@ -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 @@
__UNCONST(&_DefaultNumericLocale),
[(size_t)LC_MESSAGES] = (_locale_part_t)
__UNCONST(&_DefaultMessagesLocale),
+ [(size_t)LC_TIME] = (_locale_part_t)
+ __UNCONST(&_DefaultTimeLocale),
},
};
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/locale/nb_lc_time_misc.h
--- a/lib/libc/locale/nb_lc_time_misc.h Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/locale/nb_lc_time_misc.h Sun Apr 21 17:45:46 2013 +0000
@@ -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 @@
_PREFIX(fixup)(_TimeLocale *data)
{
_DIAGASSERT(data != NULL);
-
- _CurrentTimeLocale = data;
}
/*
diff -r 1d5e653a213b -r 4e4d88895ce5 lib/libc/time/strftime.c
--- a/lib/libc/time/strftime.c Sun Apr 21 15:42:11 2013 +0000
+++ b/lib/libc/time/strftime.c Sun Apr 21 17:45:46 2013 +0000
@@ -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 @@
#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 @@
#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 @@
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 @@
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 @@
{
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 @@
}
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 @@
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 @@
continue;
Home |
Main Index |
Thread Index |
Old Index