Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add mblen_l, mbstowcs_l, wctomb_l, mbtowc_l and wcstombs_l.
details: https://anonhg.NetBSD.org/src/rev/f648b7db6e89
branches: trunk
changeset: 786181:f648b7db6e89
user: joerg <joerg%NetBSD.org@localhost>
date: Thu Apr 18 22:22:20 2013 +0000
description:
Add mblen_l, mbstowcs_l, wctomb_l, mbtowc_l and wcstombs_l.
diffstat:
include/stdlib.h | 14 +++++-
lib/libc/locale/multibyte_c90.c | 87 ++++++++++++++++++++++++++++++----------
2 files changed, 77 insertions(+), 24 deletions(-)
diffs (175 lines):
diff -r fd2689ca6aa1 -r f648b7db6e89 include/stdlib.h
--- a/include/stdlib.h Thu Apr 18 21:54:10 2013 +0000
+++ b/include/stdlib.h Thu Apr 18 22:22:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: stdlib.h,v 1.102 2013/04/18 21:54:10 joerg Exp $ */
+/* $NetBSD: stdlib.h,v 1.103 2013/04/18 22:22:20 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -351,7 +351,17 @@
# if defined(_NETBSD_SOURCE)
quad_t strtoq_l(const char * __restrict, char ** __restrict, int, locale_t);
u_quad_t strtouq_l(const char * __restrict, char ** __restrict, int, locale_t);
-# endif
+
+int mblen_l(const char *, size_t, locale_t);
+size_t mbstowcs_l(wchar_t * __restrict, const char * __restrict, size_t,
+ locale_t);
+int wctomb_l(char *, wchar_t, locale_t);
+int mbtowc_l(wchar_t * __restrict, const char * __restrict, size_t,
+ locale_t);
+size_t wcstombs_l(char * __restrict, const wchar_t * __restrict, size_t,
+ locale_t);
+
+# endif /* _NETBSD_SOURCE */
#endif /* _POSIX_C_SOURCE >= 200809 || _NETBSD_SOURCE */
__END_DECLS
diff -r fd2689ca6aa1 -r f648b7db6e89 lib/libc/locale/multibyte_c90.c
--- a/lib/libc/locale/multibyte_c90.c Thu Apr 18 21:54:10 2013 +0000
+++ b/lib/libc/locale/multibyte_c90.c Thu Apr 18 22:22:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: multibyte_c90.c,v 1.8 2010/06/13 04:14:57 tnozaki Exp $ */
+/* $NetBSD: multibyte_c90.c,v 1.9 2013/04/18 22:22:21 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_c90.c,v 1.8 2010/06/13 04:14:57 tnozaki Exp $");
+__RCSID("$NetBSD: multibyte_c90.c,v 1.9 2013/04/18 22:22:21 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -46,19 +46,42 @@
#include "citrus_ctype.h"
#include "runetype_local.h"
-#define _RUNE_LOCALE() \
- ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE])
+#define _CITRUS_CTYPE(loc) \
+ (((_RuneLocale *)((loc)->part_impl[(size_t)LC_CTYPE]))->rl_citrus_ctype)
+
+int
+mblen_l(const char *s, size_t n, locale_t loc)
+{
+ int ret;
+ int err0;
-#define _CITRUS_CTYPE() \
- (_RUNE_LOCALE()->rl_citrus_ctype)
+ if (loc == NULL)
+ loc = _C_locale;
+
+ err0 = _citrus_ctype_mblen(_CITRUS_CTYPE(loc), s, n, &ret);
+ if (err0)
+ errno = err0;
+
+ return ret;
+}
+
int
mblen(const char *s, size_t n)
{
- int ret;
+ return mblen_l(s, n, *_current_locale());
+}
+
+size_t
+mbstowcs_l(wchar_t *pwcs, const char *s, size_t n, locale_t loc)
+{
+ size_t ret;
int err0;
- err0 = _citrus_ctype_mblen(_CITRUS_CTYPE(), s, n, &ret);
+ if (loc == NULL)
+ loc = _C_locale;
+
+ err0 = _citrus_ctype_mbstowcs(_CITRUS_CTYPE(loc), pwcs, s, n, &ret);
if (err0)
errno = err0;
@@ -68,10 +91,19 @@
size_t
mbstowcs(wchar_t *pwcs, const char *s, size_t n)
{
- size_t ret;
+ return mbstowcs_l(pwcs, s, n, *_current_locale());
+}
+
+int
+mbtowc_l(wchar_t *pw, const char *s, size_t n, locale_t loc)
+{
+ int ret;
int err0;
- err0 = _citrus_ctype_mbstowcs(_CITRUS_CTYPE(), pwcs, s, n, &ret);
+ if (loc == NULL)
+ loc = _C_locale;
+
+ err0 = _citrus_ctype_mbtowc(_CITRUS_CTYPE(loc), pw, s, n, &ret);
if (err0)
errno = err0;
@@ -81,10 +113,19 @@
int
mbtowc(wchar_t *pw, const char *s, size_t n)
{
- int ret;
+ return mbtowc_l(pw, s, n, *_current_locale());
+}
+
+size_t
+wcstombs_l(char *s, const wchar_t *wcs, size_t n, locale_t loc)
+{
+ size_t ret;
int err0;
- err0 = _citrus_ctype_mbtowc(_CITRUS_CTYPE(), pw, s, n, &ret);
+ if (loc == NULL)
+ loc = _C_locale;
+
+ err0 = _citrus_ctype_wcstombs(_CITRUS_CTYPE(loc), s, wcs, n, &ret);
if (err0)
errno = err0;
@@ -94,10 +135,19 @@
size_t
wcstombs(char *s, const wchar_t *wcs, size_t n)
{
- size_t ret;
+ return wcstombs_l(s, wcs, n, *_current_locale());
+}
+
+int
+wctomb_l(char *s, wchar_t wc, locale_t loc)
+{
+ int ret;
int err0;
- err0 = _citrus_ctype_wcstombs(_CITRUS_CTYPE(), s, wcs, n, &ret);
+ if (loc == NULL)
+ loc = _C_locale;
+
+ err0 = _citrus_ctype_wctomb(_CITRUS_CTYPE(loc), s, wc, &ret);
if (err0)
errno = err0;
@@ -107,12 +157,5 @@
int
wctomb(char *s, wchar_t wc)
{
- int ret;
- int err0;
-
- err0 = _citrus_ctype_wctomb(_CITRUS_CTYPE(), s, wc, &ret);
- if (err0)
- errno = err0;
-
- return ret;
+ return wctomb_l(s, wc, *_current_locale());
}
- Prev by Date:
[src/trunk]: src/distrib/sets/lists/debug Fix build when MKDEBUG=yes and MKRU...
- Next by Date:
[src/trunk]: src Add wcscoll_l, wcsxfrm_l, wcsncasecmp_l, wcscasecmp_l, btowc_l,
- Previous by Thread:
[src/trunk]: src/distrib/sets/lists/debug Fix build when MKDEBUG=yes and MKRU...
- Next by Thread:
[src/trunk]: src Add wcscoll_l, wcsxfrm_l, wcsncasecmp_l, wcscasecmp_l, btowc_l,
- Indexes:
Home |
Main Index |
Thread Index |
Old Index