Module Name: src Committed By: joerg Date: Thu Apr 18 23:24:27 UTC 2013
Modified Files: src/include: wchar.h src/lib/libc/include: namespace.h src/lib/libc/locale: multibyte_amd1.c wcscoll.c wcsxfrm.c src/lib/libc/string: wcscasecmp.c wcsncasecmp.c Log Message: Add wcscoll_l, wcsxfrm_l, wcsncasecmp_l, wcscasecmp_l, btowc_l, mbrlen_l, mbsinit_l, mbsrtowcs_l, wcrtomb_l, wcsrtombs_l and wctob_l. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/include/wchar.h cvs rdiff -u -r1.160 -r1.161 src/lib/libc/include/namespace.h cvs rdiff -u -r1.9 -r1.10 src/lib/libc/locale/multibyte_amd1.c cvs rdiff -u -r1.2 -r1.3 src/lib/libc/locale/wcscoll.c cvs rdiff -u -r1.3 -r1.4 src/lib/libc/locale/wcsxfrm.c cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/wcscasecmp.c \ src/lib/libc/string/wcsncasecmp.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/wchar.h diff -u src/include/wchar.h:1.33 src/include/wchar.h:1.34 --- src/include/wchar.h:1.33 Thu Apr 18 22:23:17 2013 +++ src/include/wchar.h Thu Apr 18 23:24:26 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wchar.h,v 1.33 2013/04/18 22:23:17 joerg Exp $ */ +/* $NetBSD: wchar.h,v 1.34 2013/04/18 23:24:26 joerg Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -211,6 +211,11 @@ __END_DECLS typedef struct _locale *locale_t; # define __LOCALE_T_DECLARED # endif +int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); +size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t); +int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); +int wcscasecmp_l(const wchar_t *, const wchar_t *, 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, @@ -227,6 +232,21 @@ unsigned long long int wcstoull_l(const wchar_t ** __restrict, int, locale_t); int wcwidth_l(wchar_t, locale_t); int wcswidth_l(const wchar_t *, size_t, locale_t); -#endif +#endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */ + +#if defined(_NETBSD_SOURCE) +wint_t btowc_l(int, locale_t); +size_t mbrlen_l(const char * __restrict, size_t, mbstate_t * __restrict, + locale_t); +size_t mbrtowc_l(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict, locale_t); +int mbsinit_l(const mbstate_t *, locale_t); +size_t mbsrtowcs_l(wchar_t * __restrict, const char ** __restrict, size_t, + mbstate_t * __restrict, locale_t); +size_t wcrtomb_l(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t); +size_t wcsrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t, + mbstate_t * __restrict, locale_t); +int wctob_l(wint_t, locale_t); +#endif /* _NETBSD_SOURCE */ #endif /* !_WCHAR_H_ */ Index: src/lib/libc/include/namespace.h diff -u src/lib/libc/include/namespace.h:1.160 src/lib/libc/include/namespace.h:1.161 --- src/lib/libc/include/namespace.h:1.160 Thu Apr 18 22:23:17 2013 +++ src/lib/libc/include/namespace.h Thu Apr 18 23:24:26 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: namespace.h,v 1.160 2013/04/18 22:23:17 joerg Exp $ */ +/* $NetBSD: namespace.h,v 1.161 2013/04/18 23:24:26 joerg Exp $ */ /*- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. @@ -704,8 +704,10 @@ #define wait4 _wait4 #define waitpid _waitpid #define wcscasecmp _wcscasecmp +#define wcscasecmp_l _wcscasecmp_l #define wcsdup _wcsdup #define wcsncasecmp _wcsncasecmp +#define wcsncasecmp_l _wcsncasecmp_l #define wcstof _wcstof #define wcstof_l _wcstof_l #define wcstod _wcstod Index: src/lib/libc/locale/multibyte_amd1.c diff -u src/lib/libc/locale/multibyte_amd1.c:1.9 src/lib/libc/locale/multibyte_amd1.c:1.10 --- src/lib/libc/locale/multibyte_amd1.c:1.9 Sun Jun 13 04:14:57 2010 +++ src/lib/libc/locale/multibyte_amd1.c Thu Apr 18 23:24:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: multibyte_amd1.c,v 1.9 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: multibyte_amd1.c,v 1.10 2013/04/18 23:24:27 joerg Exp $ */ /*- * Copyright (c)2002, 2008 Citrus Project, @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: multibyte_amd1.c,v 1.9 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: multibyte_amd1.c,v 1.10 2013/04/18 23:24:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -46,19 +46,22 @@ __RCSID("$NetBSD: multibyte_amd1.c,v 1.9 #include "runetype_local.h" #include "multibyte.h" -#define _RUNE_LOCALE() \ - ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE]) +#define _RUNE_LOCALE(loc) \ + ((_RuneLocale *)((loc)->part_impl[(size_t)LC_CTYPE])) -#define _CITRUS_CTYPE() \ - (_RUNE_LOCALE()->rl_citrus_ctype) +#define _CITRUS_CTYPE(loc) \ + (_RUNE_LOCALE(loc)->rl_citrus_ctype) size_t -mbrlen(const char *s, size_t n, mbstate_t *ps) +mbrlen_l(const char *s, size_t n, mbstate_t *ps, locale_t loc) { size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); + if (loc == NULL) + loc = _C_locale; + + _fixup_ps(_RUNE_LOCALE(loc), ps, s == NULL); err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n, _ps_to_private(ps), &ret); @@ -68,8 +71,14 @@ mbrlen(const char *s, size_t n, mbstate_ return ret; } +size_t +mbrlen(const char *s, size_t n, mbstate_t *ps) +{ + return mbrlen_l(s, n, ps, *_current_locale()); +} + int -mbsinit(const mbstate_t *ps) +mbsinit_l(const mbstate_t *ps, locale_t loc) { int ret; int err0; @@ -78,8 +87,11 @@ mbsinit(const mbstate_t *ps) if (ps == NULL) return 1; + if (loc == NULL) + loc = _C_locale; + if (_ps_to_runelocale(ps) == NULL) - rl = _RUNE_LOCALE(); + rl = _RUNE_LOCALE(loc); else rl = _ps_to_runelocale(ps); @@ -92,13 +104,22 @@ mbsinit(const mbstate_t *ps) return ret; } +int +mbsinit(const mbstate_t *ps) +{ + return mbsinit_l(ps, *_current_locale()); +} + size_t -mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +mbrtowc_l(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps, locale_t loc) { size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); + if (loc == NULL) + loc = _C_locale; + + _fixup_ps(_RUNE_LOCALE(loc), ps, s == NULL); err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n, _ps_to_private(ps), &ret); @@ -109,12 +130,22 @@ mbrtowc(wchar_t *pwc, const char *s, siz } size_t -mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) +mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ + return mbrtowc_l(pwc, s, n, ps, *_current_locale()); +} + +size_t +mbsrtowcs_l(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps, + locale_t loc) { size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); + if (loc == NULL) + loc = _C_locale; + + _fixup_ps(_RUNE_LOCALE(loc), ps, s == NULL); err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n, _ps_to_private(ps), &ret); @@ -125,12 +156,21 @@ mbsrtowcs(wchar_t *pwcs, const char **s, } size_t -wcrtomb(char *s, wchar_t wc, mbstate_t *ps) +mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) +{ + return mbsrtowcs_l(pwcs, s, n, ps, *_current_locale()); +} + +size_t +wcrtomb_l(char *s, wchar_t wc, mbstate_t *ps, locale_t loc) { size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); + if (loc == NULL) + loc = _C_locale; + + _fixup_ps(_RUNE_LOCALE(loc), ps, s == NULL); err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc, _ps_to_private(ps), &ret); @@ -141,12 +181,22 @@ wcrtomb(char *s, wchar_t wc, mbstate_t * } size_t -wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps) +wcrtomb(char *s, wchar_t wc, mbstate_t *ps) +{ + return wcrtomb_l(s, wc, ps, *_current_locale()); +} + +size_t +wcsrtombs_l(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps, + locale_t loc) { size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); + if (loc == NULL) + loc = _C_locale; + + _fixup_ps(_RUNE_LOCALE(loc), ps, s == NULL); err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n, _ps_to_private(ps), &ret); @@ -156,28 +206,52 @@ wcsrtombs(char *s, const wchar_t **ppwcs return ret; } +size_t +wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps) +{ + return wcsrtombs_l(s, ppwcs, n, ps, *_current_locale()); +} + wint_t -btowc(int c) +btowc_l(int c, locale_t loc) { wint_t ret; int err0; - err0 = _citrus_ctype_btowc(_CITRUS_CTYPE(), c, &ret); + if (loc == NULL) + loc = _C_locale; + + err0 = _citrus_ctype_btowc(_CITRUS_CTYPE(loc), c, &ret); if (err0) errno = err0; return ret; } +wint_t +btowc(int c) +{ + return btowc_l(c, *_current_locale()); +} + int -wctob(wint_t wc) +wctob_l(wint_t wc, locale_t loc) { int ret; int err0; - err0 = _citrus_ctype_wctob(_CITRUS_CTYPE(), wc, &ret); + if (loc == NULL) + loc = _C_locale; + + err0 = _citrus_ctype_wctob(_CITRUS_CTYPE(loc), wc, &ret); if (err0) errno = err0; return ret; } + +int +wctob(wint_t wc) +{ + return wctob_l(wc, *_current_locale()); +} \ No newline at end of file Index: src/lib/libc/locale/wcscoll.c diff -u src/lib/libc/locale/wcscoll.c:1.2 src/lib/libc/locale/wcscoll.c:1.3 --- src/lib/libc/locale/wcscoll.c:1.2 Mon Jun 25 22:32:44 2012 +++ src/lib/libc/locale/wcscoll.c Thu Apr 18 23:24:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wcscoll.c,v 1.2 2012/06/25 22:32:44 abs Exp $ */ +/* $NetBSD: wcscoll.c,v 1.3 2013/04/18 23:24:27 joerg Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,20 +28,31 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscoll.c,v 1.2 2012/06/25 22:32:44 abs Exp $"); +__RCSID("$NetBSD: wcscoll.c,v 1.3 2013/04/18 23:24:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include <assert.h> #include <wchar.h> +#include <locale.h> +#include "setlocale_local.h" /* * Compare strings with using collating information. */ int -wcscoll(const wchar_t *s1, const wchar_t *s2) +wcscoll_l(const wchar_t *s1, const wchar_t *s2, locale_t loc) { + if (loc == NULL) + loc = _C_locale; /* XXX: LC_COLLATE should be implemented. */ + /* LINTED */ (void)loc; return (wcscmp(s1, s2)); } + +int +wcscoll(const wchar_t *s1, const wchar_t *s2) +{ + return wcscoll_l(s1, s2, *_current_locale()); +} Index: src/lib/libc/locale/wcsxfrm.c diff -u src/lib/libc/locale/wcsxfrm.c:1.3 src/lib/libc/locale/wcsxfrm.c:1.4 --- src/lib/libc/locale/wcsxfrm.c:1.3 Mon Jun 25 22:32:44 2012 +++ src/lib/libc/locale/wcsxfrm.c Thu Apr 18 23:24:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wcsxfrm.c,v 1.3 2012/06/25 22:32:44 abs Exp $ */ +/* $NetBSD: wcsxfrm.c,v 1.4 2013/04/18 23:24:27 joerg Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,23 +28,28 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsxfrm.c,v 1.3 2012/06/25 22:32:44 abs Exp $"); +__RCSID("$NetBSD: wcsxfrm.c,v 1.4 2013/04/18 23:24:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include <assert.h> #include <wchar.h> +#include <locale.h> +#include "setlocale_local.h" /* * Compare strings with using collating information. */ size_t -wcsxfrm(wchar_t *s1, const wchar_t *s2, size_t n) +wcsxfrm_l(wchar_t *s1, const wchar_t *s2, size_t n, locale_t loc) { size_t len; + if (loc == NULL) + loc = _C_locale; /* XXX: LC_COLLATE should be implemented. */ + /* LINTED */(void)loc; len = wcslen(s2); if (len<n) @@ -60,3 +65,9 @@ wcsxfrm(wchar_t *s1, const wchar_t *s2, return (len); } + +size_t +wcsxfrm(wchar_t *s1, const wchar_t *s2, size_t n) +{ + return wcsxfrm_l(s1, s2, n, *_current_locale()); +} Index: src/lib/libc/string/wcscasecmp.c diff -u src/lib/libc/string/wcscasecmp.c:1.2 src/lib/libc/string/wcscasecmp.c:1.3 --- src/lib/libc/string/wcscasecmp.c:1.2 Sat Aug 26 22:45:52 2006 +++ src/lib/libc/string/wcscasecmp.c Thu Apr 18 23:24:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wcscasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $ */ +/* $NetBSD: wcscasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $ */ /* * Copyright (C) 2006 Aleksey Cheusov @@ -13,29 +13,35 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $"); +__RCSID("$NetBSD: wcscasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include <assert.h> #include <wchar.h> #include <wctype.h> +#include <locale.h> +#include "setlocale_local.h" __weak_alias(wcscasecmp,_wcscasecmp) +__weak_alias(wcscasecmp_l,_wcscasecmp_l) int -wcscasecmp(const wchar_t *s1, const wchar_t *s2) +wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc) { int lc1 = 0; int lc2 = 0; int diff = 0; + if (loc == NULL) + loc = _C_locale; + _DIAGASSERT(s1); _DIAGASSERT(s2); for (;;) { - lc1 = towlower(*s1); - lc2 = towlower(*s2); + lc1 = towlower_l(*s1, loc); + lc2 = towlower_l(*s2, loc); diff = lc1 - lc2; if (diff) @@ -48,3 +54,9 @@ wcscasecmp(const wchar_t *s1, const wcha ++s2; } } + +int +wcscasecmp(const wchar_t *s1, const wchar_t *s2) +{ + return wcscasecmp_l(s1, s2, *_current_locale()); +} Index: src/lib/libc/string/wcsncasecmp.c diff -u src/lib/libc/string/wcsncasecmp.c:1.2 src/lib/libc/string/wcsncasecmp.c:1.3 --- src/lib/libc/string/wcsncasecmp.c:1.2 Sat Aug 26 22:45:52 2006 +++ src/lib/libc/string/wcsncasecmp.c Thu Apr 18 23:24:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wcsncasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $ */ +/* $NetBSD: wcsncasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $ */ /* * Copyright (C) 2006 Aleksey Cheusov @@ -13,18 +13,21 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsncasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $"); +__RCSID("$NetBSD: wcsncasecmp.c,v 1.3 2013/04/18 23:24:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include <assert.h> #include <wchar.h> #include <wctype.h> +#include <locale.h> +#include "setlocale_local.h" __weak_alias(wcsncasecmp,_wcsncasecmp) +__weak_alias(wcsncasecmp_l,_wcsncasecmp_l) int -wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) +wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t loc) { int lc1 = 0; int lc2 = 0; @@ -33,9 +36,12 @@ wcsncasecmp(const wchar_t *s1, const wch _DIAGASSERT(s1); _DIAGASSERT(s2); + if (loc == NULL) + loc = _C_locale; + while (n--) { - lc1 = towlower (*s1); - lc2 = towlower (*s2); + lc1 = towlower_l(*s1, loc); + lc2 = towlower_l(*s2, loc); diff = lc1 - lc2; if (diff) @@ -50,3 +56,9 @@ wcsncasecmp(const wchar_t *s1, const wch return 0; } + +int +wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + return wcsncasecmp_l(s1, s2, n, *_current_locale()); +}