Module Name: src Committed By: joerg Date: Mon Aug 19 08:03:34 UTC 2013
Modified Files: src/include: langinfo.h nl_types.h wchar.h src/lib/libc/include: namespace.h src/lib/libc/locale: nl_langinfo.c wcsftime.c src/lib/libc/nls: Makefile.inc catopen.c Removed Files: src/lib/libc/nls: _catclose.c _catgets.c _catopen.c Log Message: Add nl_langinfo_l, catopen_l and wcsftime_l. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/include/langinfo.h cvs rdiff -u -r1.12 -r1.13 src/include/nl_types.h cvs rdiff -u -r1.38 -r1.39 src/include/wchar.h cvs rdiff -u -r1.166 -r1.167 src/lib/libc/include/namespace.h cvs rdiff -u -r1.15 -r1.16 src/lib/libc/locale/nl_langinfo.c cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/wcsftime.c cvs rdiff -u -r1.11 -r1.12 src/lib/libc/nls/Makefile.inc cvs rdiff -u -r1.7 -r0 src/lib/libc/nls/_catclose.c \ src/lib/libc/nls/_catopen.c cvs rdiff -u -r1.8 -r0 src/lib/libc/nls/_catgets.c cvs rdiff -u -r1.31 -r1.32 src/lib/libc/nls/catopen.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/langinfo.h diff -u src/include/langinfo.h:1.9 src/include/langinfo.h:1.10 --- src/include/langinfo.h:1.9 Thu Feb 3 04:39:32 2005 +++ src/include/langinfo.h Mon Aug 19 08:03:33 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: langinfo.h,v 1.9 2005/02/03 04:39:32 perry Exp $ */ +/* $NetBSD: langinfo.h,v 1.10 2013/08/19 08:03:33 joerg Exp $ */ /* * Written by J.T. Conklin <j...@netbsd.org> @@ -88,4 +88,14 @@ __BEGIN_DECLS char *nl_langinfo(nl_item); __END_DECLS +#if defined(_NETBSD_SOURCE) +# ifndef __LOCALE_T_DECLARED +typedef struct _locale *locale_t; +# define __LOCALE_T_DECLARED +# endif +__BEGIN_DECLS +char *nl_langinfo_l(nl_item, locale_t); +__END_DECLS +#endif + #endif /* _LANGINFO_H_ */ Index: src/include/nl_types.h diff -u src/include/nl_types.h:1.12 src/include/nl_types.h:1.13 --- src/include/nl_types.h:1.12 Mon Apr 28 20:22:54 2008 +++ src/include/nl_types.h Mon Aug 19 08:03:33 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: nl_types.h,v 1.12 2008/04/28 20:22:54 martin Exp $ */ +/* $NetBSD: nl_types.h,v 1.13 2013/08/19 08:03:33 joerg Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -83,9 +83,18 @@ typedef long nl_item; __BEGIN_DECLS nl_catd catopen(const char *, int); -char *catgets(nl_catd, int, int, const char *) - __attribute__((__format_arg__(4))); +char *catgets(nl_catd, int, int, const char *) __format_arg(4); int catclose(nl_catd); __END_DECLS +#if defined(_NETBSD_SOURCE) +# ifndef __LOCALE_T_DECLARED +typedef struct _locale *locale_t; +# define __LOCALE_T_DECLARED +# endif +__BEGIN_DECLS +nl_catd catopen_l(const char *, int, locale_t); +__END_DECLS +#endif + #endif /* _NL_TYPES_H_ */ Index: src/include/wchar.h diff -u src/include/wchar.h:1.38 src/include/wchar.h:1.39 --- src/include/wchar.h:1.38 Tue May 28 16:57:56 2013 +++ src/include/wchar.h Mon Aug 19 08:03:33 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wchar.h,v 1.38 2013/05/28 16:57:56 joerg Exp $ */ +/* $NetBSD: wchar.h,v 1.39 2013/08/19 08:03:33 joerg Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -222,6 +222,9 @@ size_t wcsxfrm_l(wchar_t *, const wchar_ int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); +size_t wcsftime_l(wchar_t * __restrict, size_t, const wchar_t * __restrict, + const struct tm * __restrict, locale_t); + float wcstof_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t); double wcstod_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t); long double wcstold_l(const wchar_t * __restrict, wchar_t ** __restrict, Index: src/lib/libc/include/namespace.h diff -u src/lib/libc/include/namespace.h:1.166 src/lib/libc/include/namespace.h:1.167 --- src/lib/libc/include/namespace.h:1.166 Tue Apr 30 00:45:04 2013 +++ src/lib/libc/include/namespace.h Mon Aug 19 08:03:33 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: namespace.h,v 1.166 2013/04/30 00:45:04 joerg Exp $ */ +/* $NetBSD: namespace.h,v 1.167 2013/08/19 08:03:33 joerg Exp $ */ /*- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. @@ -37,6 +37,7 @@ #define catclose _catclose #define catgets _catgets #define catopen _catopen +#define catopen_l _catopen_l #define daylight _daylight #define difftime _difftime #define devname_r _devname_r @@ -486,6 +487,7 @@ #if 0 #define nlist _nlist #endif +#define nl_langinfo_l _nl_langinfo_l #define nrand48 _nrand48 #define ntp_adjtime _ntp_adjtime #define nsdispatch _nsdispatch @@ -741,6 +743,7 @@ #define wcscasecmp _wcscasecmp #define wcscasecmp_l _wcscasecmp_l #define wcsdup _wcsdup +#define wcsftime_l _wcsftime_l #define wcsncasecmp _wcsncasecmp #define wcsncasecmp_l _wcsncasecmp_l #define wcstof _wcstof Index: src/lib/libc/locale/nl_langinfo.c diff -u src/lib/libc/locale/nl_langinfo.c:1.15 src/lib/libc/locale/nl_langinfo.c:1.16 --- src/lib/libc/locale/nl_langinfo.c:1.15 Sat May 22 13:15:59 2010 +++ src/lib/libc/locale/nl_langinfo.c Mon Aug 19 08:03:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: nl_langinfo.c,v 1.15 2010/05/22 13:15:59 tnozaki Exp $ */ +/* $NetBSD: nl_langinfo.c,v 1.16 2013/08/19 08:03:34 joerg Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -27,10 +27,9 @@ */ #include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nl_langinfo.c,v 1.15 2010/05/22 13:15:59 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: nl_langinfo.c,v 1.16 2013/08/19 08:03:34 joerg Exp $"); +#include "namespace.h" #include <sys/types.h> #include <langinfo.h> #define __SETLOCALE_SOURCE__ @@ -39,14 +38,23 @@ __RCSID("$NetBSD: nl_langinfo.c,v 1.15 2 #include "setlocale_local.h" +__weak_alias(nl_langinfo_l, _nl_langinfo_l) + char * nl_langinfo(nl_item item) { + + return nl_langinfo_l(item, _current_locale()); +} + +char * +nl_langinfo_l(nl_item item, locale_t loc) +{ const char *s; s = NULL; if (item >= D_T_FMT && item <= ALT_DIGITS) - s = _current_cache()->items[(size_t)item]; + s = loc->cache->items[(size_t)item]; if (s == NULL) s = ""; return __UNCONST(s); Index: src/lib/libc/locale/wcsftime.c diff -u src/lib/libc/locale/wcsftime.c:1.3 src/lib/libc/locale/wcsftime.c:1.4 --- src/lib/libc/locale/wcsftime.c:1.3 Mon May 21 15:32:17 2007 +++ src/lib/libc/locale/wcsftime.c Mon Aug 19 08:03:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wcsftime.c,v 1.3 2007/05/21 15:32:17 tnozaki Exp $ */ +/* $NetBSD: wcsftime.c,v 1.4 2013/08/19 08:03:34 joerg Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins * All rights reserved. @@ -26,20 +26,21 @@ */ #include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $"); -#else -__RCSID("$NetBSD: wcsftime.c,v 1.3 2007/05/21 15:32:17 tnozaki Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: wcsftime.c,v 1.4 2013/08/19 08:03:34 joerg Exp $"); +#define __SETLOCALE_SOURCE__ +#include "namespace.h" #include <errno.h> #include <limits.h> +#include <locale.h> #include <stdlib.h> #include <time.h> #include <wchar.h> +#include "setlocale_local.h" + +__weak_alias(wcsftime_l, _wcsftime_l) + /* * Convert date and time to a wide-character string. * @@ -57,6 +58,13 @@ size_t wcsftime(wchar_t *wcs, size_t maxsize, const wchar_t *format, const struct tm *timeptr) { + return wcsftime_l(wcs, maxsize, format, timeptr, _current_locale()); +} + +size_t +wcsftime_l(wchar_t *wcs, size_t maxsize, + const wchar_t *format, const struct tm *timeptr, locale_t loc) +{ char *dst, *dstp, *sformat; size_t n, sflen; int sverrno; @@ -67,12 +75,12 @@ wcsftime(wchar_t *wcs, size_t maxsize, * Convert the supplied format string to a multibyte representation * for strftime(), which only handles single-byte characters. */ - sflen = wcstombs(NULL, format, 0); + sflen = wcstombs_l(NULL, format, 0, loc); if (sflen == (size_t)-1) goto error; if ((sformat = malloc(sflen + 1)) == NULL) goto error; - wcstombs(sformat, format, sflen + 1); + wcstombs_l(sformat, format, sflen + 1, loc); /* * Allocate memory for longest multibyte sequence that will fit @@ -80,7 +88,7 @@ wcsftime(wchar_t *wcs, size_t maxsize, * Then, copy and convert the result back into wide characters in * the caller's buffer. */ - if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) { + if (SIZE_T_MAX / MB_CUR_MAX_L(loc) <= maxsize) { /* maxsize is preposterously large - avoid int. overflow. */ errno = EINVAL; goto error; @@ -88,10 +96,10 @@ wcsftime(wchar_t *wcs, size_t maxsize, dst = malloc(maxsize * MB_CUR_MAX); if (dst == NULL) goto error; - if (strftime(dst, maxsize, sformat, timeptr) == 0) + if (strftime_l(dst, maxsize, sformat, timeptr, loc) == 0) goto error; dstp = dst; - n = mbstowcs(wcs, dstp, maxsize); + n = mbstowcs_l(wcs, dstp, maxsize, loc); if (n == (size_t)-2 || n == (size_t)-1) goto error; Index: src/lib/libc/nls/Makefile.inc diff -u src/lib/libc/nls/Makefile.inc:1.11 src/lib/libc/nls/Makefile.inc:1.12 --- src/lib/libc/nls/Makefile.inc:1.11 Fri Jan 20 16:31:30 2012 +++ src/lib/libc/nls/Makefile.inc Mon Aug 19 08:03:34 2013 @@ -1,12 +1,9 @@ -# $NetBSD: Makefile.inc,v 1.11 2012/01/20 16:31:30 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.12 2013/08/19 08:03:34 joerg Exp $ .PATH: ${.CURDIR}/nls SRCS+= catclose.c catgets.c catopen.c MAN+= catclose.3 catgets.3 catopen.3 -# indirect reference stubs, to be removed soon. -SRCS+= _catclose.c _catgets.c _catopen.c - CPPFLAGS.catopen.c+= -I${LIBCDIR}/citrus Index: src/lib/libc/nls/catopen.c diff -u src/lib/libc/nls/catopen.c:1.31 src/lib/libc/nls/catopen.c:1.32 --- src/lib/libc/nls/catopen.c:1.31 Mon Jul 30 23:02:41 2012 +++ src/lib/libc/nls/catopen.c Mon Aug 19 08:03:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: catopen.c,v 1.31 2012/07/30 23:02:41 yamt Exp $ */ +/* $NetBSD: catopen.c,v 1.32 2013/08/19 08:03:34 joerg Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -30,11 +30,10 @@ */ #include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: catopen.c,v 1.31 2012/07/30 23:02:41 yamt Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: catopen.c,v 1.32 2013/08/19 08:03:34 joerg Exp $"); #define _NLS_PRIVATE +#define __SETLOCALE_SOURCE__ #include "namespace.h" #include <sys/param.h> @@ -55,20 +54,27 @@ __RCSID("$NetBSD: catopen.c,v 1.31 2012/ #include "citrus_region.h" #include "citrus_lookup.h" #include "citrus_aliasname_local.h" +#include "setlocale_local.h" #define NLS_ALIAS_DB "/usr/share/nls/nls.alias" #define NLS_DEFAULT_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L" #define NLS_DEFAULT_LANG "C" -#ifdef __weak_alias __weak_alias(catopen, _catopen) -#endif +__weak_alias(catopen_l, _catopen_l) static nl_catd load_msgcat(const char *); nl_catd -_catopen(const char *name, int oflag) +catopen(const char *name, int oflag) +{ + + return catopen_l(name, oflag, _current_locale()); +} + +nl_catd +catopen_l(const char *name, int oflag, locale_t loc) { char tmppath[PATH_MAX+1]; const char *nlspath; @@ -88,11 +94,11 @@ _catopen(const char *name, int oflag) if (issetugid() || (nlspath = getenv("NLSPATH")) == NULL) nlspath = NLS_DEFAULT_PATH; /* - * histrical note: + * Historical note: * http://www.hauN.org/ml/b-l-j/a/800/828.html (in japanese) */ if (oflag == NL_CAT_LOCALE) { - lang = setlocale(LC_MESSAGES, NULL); + lang = loc->part_name[LC_MESSAGES]; } else { lang = getenv("LANG"); }