Diff below adds mbsnrtowcs() and wcsnrtombs(), which are new POSIX
2008 functions. I'd appreciate if someone could run this through a
bulk build and let me know if anything breaks or misbehaves.
Thanks!
Index: include/wchar.h
===
RCS file: /home/mdempsky/anoncvs/cvs/src/include/wchar.h,v
retrieving revision 1.22
diff -u -p -r1.22 wchar.h
--- include/wchar.h 5 Jan 2012 20:37:50 - 1.22
+++ include/wchar.h 25 May 2012 06:01:50 -
@@ -158,6 +158,11 @@ unsigned long int wcstoul(const wchar_t
wchar_t*wcsdup(const wchar_t *);
int wcscasecmp(const wchar_t *, const wchar_t *);
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
+
+size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
+size_t, mbstate_t * __restrict);
+size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
+size_t, mbstate_t * __restrict);
#endif
#if __ISO_C_VISIBLE >= 1999
Index: lib/libc/locale/multibyte_citrus.c
===
RCS file: /home/mdempsky/anoncvs/cvs/src/lib/libc/locale/multibyte_citrus.c,v
retrieving revision 1.1
diff -u -p -r1.1 multibyte_citrus.c
--- lib/libc/locale/multibyte_citrus.c 27 Jul 2010 16:59:04 - 1.1
+++ lib/libc/locale/multibyte_citrus.c 25 May 2012 16:45:00 -
@@ -30,6 +30,7 @@
#include
#include
#include
+#include
#include
#include "citrus_ctype.h"
@@ -65,7 +66,19 @@ mbrtowc(wchar_t *pwc, const char *s, siz
}
size_t
-mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps)
+mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps)
+{
+ static mbstate_t mbs;
+ struct _citrus_ctype_rec *cc;
+
+ if (ps == NULL)
+ ps = &mbs;
+ return (mbsnrtowcs(dst, src, SIZE_MAX, len, ps));
+}
+
+size_t
+mbsnrtowcs(wchar_t *dst, const char **src, size_t nmc, size_t len,
+mbstate_t *ps)
{
static mbstate_t mbs;
struct _citrus_ctype_rec *cc;
@@ -73,7 +86,8 @@ mbsrtowcs(wchar_t *pwcs, const char **s,
if (ps == NULL)
ps = &mbs;
cc = _CurrentRuneLocale->rl_citrus_ctype;
- return (*cc->cc_ops->co_mbsrtowcs)(pwcs, s, n, _ps_to_private(ps));
+ return (*cc->cc_ops->co_mbsnrtowcs)(dst, src, nmc, len,
+ _ps_to_private(ps));
}
size_t
@@ -89,7 +103,18 @@ wcrtomb(char *s, wchar_t wc, mbstate_t *
}
size_t
-wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps)
+wcsrtombs(char *dst, const wchar_t **src, size_t len, mbstate_t *ps)
+{
+ static mbstate_t mbs;
+
+ if (ps == NULL)
+ ps = &mbs;
+ return (wcsnrtombs(dst, src, SIZE_MAX, len, ps));
+}
+
+size_t
+wcsnrtombs(char *dst, const wchar_t **src, size_t nwc, size_t len,
+mbstate_t *ps)
{
static mbstate_t mbs;
struct _citrus_ctype_rec *cc;
@@ -97,5 +122,6 @@ wcsrtombs(char *s, const wchar_t **ppwcs
if (ps == NULL)
ps = &mbs;
cc = _CurrentRuneLocale->rl_citrus_ctype;
- return (*cc->cc_ops->co_wcsrtombs)(s, ppwcs, n, _ps_to_private(ps));
+ return (*cc->cc_ops->co_wcsnrtombs)(dst, src, nwc, len,
+ _ps_to_private(ps));
}
Index: lib/libc/citrus/citrus_ctype_local.h
===
RCS file: /home/mdempsky/anoncvs/cvs/src/lib/libc/citrus/citrus_ctype_local.h,v
retrieving revision 1.2
diff -u -p -r1.2 citrus_ctype_local.h
--- lib/libc/citrus/citrus_ctype_local.h27 Jul 2010 16:59:03 -
1.2
+++ lib/libc/citrus/citrus_ctype_local.h25 May 2012 01:36:32 -
@@ -36,43 +36,45 @@ size_t _citrus_##_e_##_ctype_mbrtowc(wch
const char * __restrict, size_t, \
void * __restrict); \
int_citrus_##_e_##_ctype_mbsinit(const void * __restrict); \
-size_t _citrus_##_e_##_ctype_mbsrtowcs(wchar_t * __restrict, \
- const char ** __restrict, \
- size_t, void * __restrict); \
+size_t _citrus_##_e_##_ctype_mbsnrtowcs(wchar_t * __restrict, \
+const char ** __restrict, \
+size_t, size_t,\
+void * __restrict);\
size_t _citrus_##_e_##_ctype_wcrtomb(char * __restrict, wchar_t, \
void * __restrict); \
-size_t _citrus_##_e_##_ctype_wcsrtombs(char * __restrict, \
- const wchar_t ** __restrict,\
- size_t, void * __restrict); \
+size_t _citrus_##_e_##_ctype_wcsnrtombs(char * __restrict, \
+const wchar_t ** __rest