Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add nl_langinfo_l, catopen_l and wcsftime_l.



details:   https://anonhg.NetBSD.org/src/rev/e57eb79762d1
branches:  trunk
changeset: 789456:e57eb79762d1
user:      joerg <joerg%NetBSD.org@localhost>
date:      Mon Aug 19 08:03:33 2013 +0000

description:
Add nl_langinfo_l, catopen_l and wcsftime_l.

diffstat:

 include/langinfo.h            |  12 +++++++++++-
 include/nl_types.h            |  15 ++++++++++++---
 include/wchar.h               |   5 ++++-
 lib/libc/include/namespace.h  |   5 ++++-
 lib/libc/locale/nl_langinfo.c |  18 +++++++++++++-----
 lib/libc/locale/wcsftime.c    |  34 +++++++++++++++++++++-------------
 lib/libc/nls/Makefile.inc     |   5 +----
 lib/libc/nls/_catclose.c      |  26 --------------------------
 lib/libc/nls/_catgets.c       |  26 --------------------------
 lib/libc/nls/_catopen.c       |  26 --------------------------
 lib/libc/nls/catopen.c        |  24 +++++++++++++++---------
 11 files changed, 81 insertions(+), 115 deletions(-)

diffs (truncated from 417 to 300 lines):

diff -r e775ea86545c -r e57eb79762d1 include/langinfo.h
--- a/include/langinfo.h        Mon Aug 19 07:18:42 2013 +0000
+++ b/include/langinfo.h        Mon Aug 19 08:03:33 2013 +0000
@@ -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 <jtc%NetBSD.org@localhost>
@@ -88,4 +88,14 @@
 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_ */
diff -r e775ea86545c -r e57eb79762d1 include/nl_types.h
--- a/include/nl_types.h        Mon Aug 19 07:18:42 2013 +0000
+++ b/include/nl_types.h        Mon Aug 19 08:03:33 2013 +0000
@@ -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 @@
 
 __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_ */
diff -r e775ea86545c -r e57eb79762d1 include/wchar.h
--- a/include/wchar.h   Mon Aug 19 07:18:42 2013 +0000
+++ b/include/wchar.h   Mon Aug 19 08:03:33 2013 +0000
@@ -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 @@
 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,
diff -r e775ea86545c -r e57eb79762d1 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h      Mon Aug 19 07:18:42 2013 +0000
+++ b/lib/libc/include/namespace.h      Mon Aug 19 08:03:33 2013 +0000
@@ -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
diff -r e775ea86545c -r e57eb79762d1 lib/libc/locale/nl_langinfo.c
--- a/lib/libc/locale/nl_langinfo.c     Mon Aug 19 07:18:42 2013 +0000
+++ b/lib/libc/locale/nl_langinfo.c     Mon Aug 19 08:03:33 2013 +0000
@@ -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 @@
 
 #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);
diff -r e775ea86545c -r e57eb79762d1 lib/libc/locale/wcsftime.c
--- a/lib/libc/locale/wcsftime.c        Mon Aug 19 07:18:42 2013 +0000
+++ b/lib/libc/locale/wcsftime.c        Mon Aug 19 08:03:33 2013 +0000
@@ -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 @@
 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 @@
         * 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 @@
         * 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 @@
        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;
 
diff -r e775ea86545c -r e57eb79762d1 lib/libc/nls/Makefile.inc
--- a/lib/libc/nls/Makefile.inc Mon Aug 19 07:18:42 2013 +0000
+++ b/lib/libc/nls/Makefile.inc Mon Aug 19 08:03:33 2013 +0000
@@ -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
 
diff -r e775ea86545c -r e57eb79762d1 lib/libc/nls/_catclose.c
--- a/lib/libc/nls/_catclose.c  Mon Aug 19 07:18:42 2013 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*     $NetBSD: _catclose.c,v 1.7 2005/09/13 01:44:09 christos Exp $   */
-
-/*
- * Written by J.T. Conklin, 10/05/94
- * Public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _catclose.c,v 1.7 2005/09/13 01:44:09 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#if defined(__indr_reference)
-__indr_reference(_catclose, catclose)
-#else
-
-#include <nl_types.h>
-int    _catclose(nl_catd);
-
-int
-catclose(nl_catd catd)
-{
-       return _catclose(catd);
-}
-
-#endif
diff -r e775ea86545c -r e57eb79762d1 lib/libc/nls/_catgets.c
--- a/lib/libc/nls/_catgets.c   Mon Aug 19 07:18:42 2013 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*     $NetBSD: _catgets.c,v 1.8 2005/09/13 01:44:10 christos Exp $    */
-
-/*
- * Written by J.T. Conklin, 10/05/94
- * Public domain.
- */
-



Home | Main Index | Thread Index | Old Index