diff -uNrBw libc.orig/citrus/Makefile.inc libc/citrus/Makefile.inc --- libc.orig/citrus/Makefile.inc 2010-05-30 17:28:53.000000000 +0900 +++ libc/citrus/Makefile.inc 2010-11-20 23:00:22.000000000 +0900 @@ -18,6 +18,7 @@ citrus_lc_messages.c CPPFLAGS.citrus_bcs_strtol.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib CPPFLAGS.citrus_bcs_strtoul.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib +CPPFLAGS.citrus_ctype_fallback.c+= -I${LIBCDIR}/locale CPPFLAGS.citrus_lc_ctype.c+= -I${LIBCDIR}/locale CPPFLAGS.citrus_lc_monetary.c+= -I${LIBCDIR}/locale CPPFLAGS.citrus_lc_numeric.c+= -I${LIBCDIR}/locale diff -uNrBw libc.orig/citrus/citrus_ctype.c libc/citrus/citrus_ctype.c --- libc.orig/citrus/citrus_ctype.c 2008-06-15 01:01:07.000000000 +0900 +++ libc/citrus/citrus_ctype.c 2010-11-20 23:00:22.000000000 +0900 @@ -92,6 +92,10 @@ cc->cc_ops->co_wctob = &_citrus_ctype_wctob_fallback; /* FALLTHROUGH */ case 0x00000002: + cc->cc_ops->co_mbsnrtowcs = &_citrus_ctype_mbsnrtowcs_fallback; + cc->cc_ops->co_wcsnrtombs = &_citrus_ctype_wcsnrtombs_fallback; + /* FALLTHROUGH */ + case 0x00000003: /* FALLTHROUGH */ default: break; @@ -113,7 +117,9 @@ cc->cc_ops->co_wcstombs == NULL || cc->cc_ops->co_wctomb == NULL || cc->cc_ops->co_btowc == NULL || - cc->cc_ops->co_wctob == NULL) + cc->cc_ops->co_wctob == NULL || + cc->cc_ops->co_mbsnrtowcs == NULL || + cc->cc_ops->co_wcsnrtombs == NULL) goto bad; /* init and get closure */ diff -uNrBw libc.orig/citrus/citrus_ctype.h libc/citrus/citrus_ctype.h --- libc.orig/citrus/citrus_ctype.h 2003-03-06 05:18:15.000000000 +0900 +++ libc/citrus/citrus_ctype.h 2010-11-20 23:00:22.000000000 +0900 @@ -165,6 +165,28 @@ return (*cc->cc_ops->co_wctob)(cc, c, cresult); } +static __inline int +_citrus_ctype_mbsnrtowcs(_citrus_ctype_t __restrict cc, + wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + _DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsnrtowcs && nresult); + return (*cc->cc_ops->co_mbsnrtowcs)(cc, dst, src, + slen, dlen, pspriv, nresult); +} + +static __inline int +_citrus_ctype_wcsnrtombs(_citrus_ctype_t __restrict cc, + char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + _DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcsnrtombs && nresult); + return (*cc->cc_ops->co_wcsnrtombs)(cc, dst, src, + slen, dlen, pspriv, nresult); +} + extern _citrus_ctype_rec_t _citrus_ctype_default; #endif diff -uNrBw libc.orig/citrus/citrus_ctype_fallback.c libc/citrus/citrus_ctype_fallback.c --- libc.orig/citrus/citrus_ctype_fallback.c 2003-06-27 23:52:25.000000000 +0900 +++ libc/citrus/citrus_ctype_fallback.c 2010-11-20 23:00:22.000000000 +0900 @@ -35,15 +35,20 @@ #include #include -#include +#include +#include +#include #include #include -#include +#include #include "citrus_module.h" #include "citrus_ctype.h" #include "citrus_ctype_fallback.h" +#include "runetype_local.h" +#include "multibyte.h" + /* * for ABI version >= 0x00000002 */ @@ -53,11 +58,7 @@ int c, wint_t * __restrict wcresult) { char mb; - /* - * what we need is _PRIVSIZE - * and we know that it's smaller than sizeof(mbstate_t). - */ - char pspriv[sizeof(mbstate_t)]; + char pspriv[_PRIVSIZE]; wchar_t wc; size_t nr; int err; @@ -84,11 +85,7 @@ _citrus_ctype_wctob_fallback(_citrus_ctype_rec_t * __restrict cc, wint_t wc, int * __restrict cresult) { - /* - * what we need is _PRIVSIZE - * and we know that it's smaller than sizeof(mbstate_t). - */ - char pspriv[sizeof(mbstate_t)]; + char pspriv[_PRIVSIZE]; char buf[MB_LEN_MAX]; size_t nr; int err; @@ -108,3 +105,107 @@ return 0; } + +/* + * for ABI version >= 0x00000003 + */ + +int +/*ARGSUSED*/ +_citrus_ctype_mbsnrtowcs_fallback(_citrus_ctype_rec_t * __restrict cc, + wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, void * __restrict ps, size_t * __restrict nresult) +{ + const char *s; + size_t n, len; + int err; + wchar_t dummy; + + s = *src; + n = slen; + if (dst == NULL) { + while (n > 0) { + err = _citrus_ctype_mbrtowc(cc, + &dummy, s, n, ps, &len); + if (err) + goto ilseq; + if (len == (size_t)-2 || dummy == L'\0') + break; + s += len, n -= len; + } + } else { + while (dlen > 0 && n > 0) { + err = _citrus_ctype_mbrtowc(cc, dst, s, n, ps, &len); + if (err) + goto ilseq; + if (len == (size_t)-2 || *dst == L'\0') + break; + ++dst, --dlen; + s += len, n -= len; + } + } + *nresult = slen - n; + return 0; + +ilseq: + *nresult = (size_t)-1; + return err; +} + +int +/*ARGSUSED*/ +_citrus_ctype_wcsnrtombs_fallback(_citrus_ctype_rec_t * __restrict cc, + char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, void * __restrict ps, size_t * __restrict nresult) +{ + const wchar_t *s; + size_t n, len; + int err; + char dummy[MB_LEN_MAX], sv[_PRIVSIZE]; + + s = *src; + if (dst == NULL) { + n = (size_t)0; + while (slen > 0) { + memcpy((void *)&sv[0], (const void *)ps, sizeof(sv)); + err = _citrus_ctype_wcrtomb(cc, + &dummy[0], *s, ps, &len); + if (err) + goto ilseq; + if (n + len > dlen) { + memcpy(ps, (const void *)&sv[0], sizeof(sv)); + break; + } + n += len; + if (*s == L'\0') + break; + ++s, --slen; + } + *nresult = n; + } else { + n = dlen; + while (n > 0 && slen > 0) { + memcpy((void *)&sv[0], (const void *)ps, sizeof(sv)); + err = _citrus_ctype_wcrtomb(cc, + &dummy[0], *s, ps, &len); + if (err) + goto ilseq; + if (n < len) { + memcpy(ps, (const void *)&sv[0], sizeof(sv)); + break; + } + dst += len, n -= len; + if (*s == L'\0') + break; + ++s, --slen; + } + *src = s; + *nresult = dlen - n; + } + return 0; + +ilseq: + *nresult = (size_t)-1; + return err; +} + diff -uNrBw libc.orig/citrus/citrus_ctype_fallback.h libc/citrus/citrus_ctype_fallback.h --- libc.orig/citrus/citrus_ctype_fallback.h 2003-03-06 05:18:15.000000000 +0900 +++ libc/citrus/citrus_ctype_fallback.h 2010-11-20 23:00:23.000000000 +0900 @@ -35,4 +35,13 @@ int _citrus_ctype_wctob_fallback(_citrus_ctype_rec_t * __restrict, wint_t, int * __restrict); +/* fallback functions for 0x00000003 */ +int _citrus_ctype_mbsnrtowcs_fallback(_citrus_ctype_rec_t * __restrict, + wchar_t * __restrict, const char ** __restrict, + size_t, size_t, void * __restrict, size_t * __restrict); + +int _citrus_ctype_wcsnrtombs_fallback(_citrus_ctype_rec_t * __restrict, + char * __restrict, const wchar_t ** __restrict, + size_t, size_t, void * __restrict, size_t * __restrict); + #endif diff -uNrBw libc.orig/citrus/citrus_ctype_local.h libc/citrus/citrus_ctype_local.h --- libc.orig/citrus/citrus_ctype_local.h 2008-02-09 23:56:20.000000000 +0900 +++ libc/citrus/citrus_ctype_local.h 2010-11-20 23:00:23.000000000 +0900 @@ -87,7 +87,13 @@ static int _citrus_##_e_##_ctype_btowc(_citrus_ctype_rec_t * __restrict, \ int, wint_t * __restrict); \ static int _citrus_##_e_##_ctype_wctob(_citrus_ctype_rec_t * __restrict, \ - wint_t, int * __restrict) + wint_t, int * __restrict); \ +static int _citrus_##_e_##_ctype_mbsnrtowcs(_citrus_ctype_rec_t * __restrict, \ + wchar_t * __restrict, const char ** __restrict, size_t, size_t, \ + void * __restrict, size_t * __restrict); \ +static int _citrus_##_e_##_ctype_wcsnrtombs(_citrus_ctype_rec_t * __restrict, \ + char * __restrict, const wchar_t ** __restrict, size_t, size_t, \ + void * __restrict, size_t * __restrict) #define _CITRUS_CTYPE_DEF_OPS(_e_) \ _citrus_ctype_ops_rec_t _citrus_##_e_##_ctype_ops = { \ @@ -107,7 +113,9 @@ /* co_wcstombs */ &_citrus_##_e_##_ctype_wcstombs, \ /* co_wctomb */ &_citrus_##_e_##_ctype_wctomb, \ /* co_btowc */ &_citrus_##_e_##_ctype_btowc, \ - /* co_wctob */ &_citrus_##_e_##_ctype_wctob \ + /* co_wctob */ &_citrus_##_e_##_ctype_wctob, \ + /* co_mbsnrtowcs */ &_citrus_##_e_##_ctype_mbsnrtowcs, \ + /* co_wcsnrtombs */ &_citrus_##_e_##_ctype_wcsnrtombs \ } typedef struct _citrus_ctype_ops_rec _citrus_ctype_ops_rec_t; @@ -152,6 +160,14 @@ (_citrus_ctype_rec_t * __restrict, int, wint_t * __restrict); typedef int (*_citrus_ctype_wctob_t) (_citrus_ctype_rec_t * __restrict, wint_t, int * __restrict); +typedef int (*_citrus_ctype_mbsnrtowcs_t) + (_citrus_ctype_rec_t * __restrict, + wchar_t * __restrict, const char ** __restrict, size_t, size_t, + void * __restrict, size_t * __restrict); +typedef int (*_citrus_ctype_wcsnrtombs_t) + (_citrus_ctype_rec_t * __restrict, + char * __restrict, const wchar_t ** __restrict, size_t, size_t, + void * __restrict, size_t * __restrict); /* * ABI Version change log: @@ -160,8 +176,11 @@ * 0x00000002 * ops record: btowc and wctob are added. * ctype record: unchanged. + * 0x00000003 + * ops record: mbsnrtowc and wcsnrtombs are added. + * ctype record: unchanged. */ -#define _CITRUS_CTYPE_ABI_VERSION 0x00000002 +#define _CITRUS_CTYPE_ABI_VERSION 0x00000003 struct _citrus_ctype_ops_rec { uint32_t co_abi_version; /* version 0x00000001 */ @@ -182,6 +201,9 @@ /* version 0x00000002 */ _citrus_ctype_btowc_t co_btowc; _citrus_ctype_wctob_t co_wctob; + /* version 0x00000003 */ + _citrus_ctype_mbsnrtowcs_t co_mbsnrtowcs; + _citrus_ctype_wcsnrtombs_t co_wcsnrtombs; }; #define _CITRUS_DEFAULT_CTYPE_NAME "NONE" diff -uNrBw libc.orig/citrus/citrus_ctype_template.h libc/citrus/citrus_ctype_template.h --- libc.orig/citrus/citrus_ctype_template.h 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/citrus_ctype_template.h 2010-11-20 23:00:23.000000000 +0900 @@ -721,3 +721,139 @@ return 0; } + +static __inline int +/*ARGSUSED*/ +_FUNCNAME(mbsnrtowcs_priv)(_ENCODING_INFO * __restrict ei, + wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, _ENCODING_STATE * __restrict psenc, + size_t * __restrict nresult) +{ + size_t n, len; + const char *s; + int err; + wchar_t dummy; + + n = slen; + if (dst == NULL) { + s = *src; + while (n > 0) { + err = _FUNCNAME(mbrtowc_priv)(ei, + &dummy, &s, n, psenc, &len); + if (err) + goto ilseq; + if (len == (size_t)-2 || dummy == L'\0') + break; + n -= len; + } + } else { + while (dlen > 0 && n > 0) { + err = _FUNCNAME(mbrtowc_priv)(ei, + dst, src, n, psenc, &len); + if (err) + goto ilseq; + if (len == (size_t)-2 || *dst == L'\0') + break; + ++dst, --dlen; + n -= len; + } + } + *nresult = slen - n; + return 0; + +ilseq: + *nresult = (size_t)-1; + return err; +} + +static int +/*ARGSUSED*/ +_FUNCNAME(ctype_mbsnrtowcs)(_citrus_ctype_rec_t * __restrict cc, + wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + int err = 0; + _ENCODING_INFO *ei; + _ENCODING_STATE *psenc; + + ei = _CEI_TO_EI(_TO_CEI(cl)); + _RESTART_BEGIN(mbsnrtowcs, _TO_CEI(cl), pspriv, psenc); + err = _FUNCNAME(mbsnrtowcs_priv)(ei, dst, src, + slen, dlen, psenc, nresult); + _RESTART_END(mbsnrtowcs, _TO_CEI(cl), pspriv, psenc); + + return err; +} + +static __inline int +/*ARGSUSED*/ +_FUNCNAME(wcsnrtombs_priv)(_ENCODING_INFO * __restrict ei, + char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, _ENCODING_STATE * __restrict psenc, + size_t * __restrict nresult) +{ + const wchar_t *s; + size_t n, len; + int err; + char dummy[MB_LEN_MAX]; + + s = *src; + if (dst == NULL) { + n = (size_t)0; + while (slen > 0) { + err = _FUNCNAME(wcrtomb_priv)(ei, + &dummy[0], *s, sizeof(dummy), psenc, &len); + if (err) + goto ilseq; + n += len; + if (*s == L'\0') + break; + ++s, --slen; + } + *nresult = n; + } else { + n = dlen; + while (n > 0 && slen > 0) { + err = _FUNCNAME(wcrtomb_priv)(ei, + dst, *s, n, psenc, &len); + if (err) { + if (err == E2BIG) + break; + goto ilseq; + } + dst += len, n -= len + if (*s == L'\0') + break; + ++s, --slen; + } + *src = s; + *nresult = dlen - n; + } + return 0; + +ilseq: + *nresult = (size_t)-1; + return err; +} + +static int +/*ARGSUSED*/ +_FUNCNAME(ctype_wcsnrtombs)(_citrus_ctype_rec_t * __restrict cc, + char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + int err = 0; + _ENCODING_INFO *ei; + _ENCODING_STATE *psenc; + + ei = _CEI_TO_EI(_TO_CEI(cl)); + _RESTART_BEGIN(wcsnrtombs, _TO_CEI(cl), pspriv, psenc); + err = _FUNCNAME(wcsnrtombs_priv)(ei, dst, src, + slen, dlen, psenc, nresult); + _RESTART_END(wcsnrtombs, _TO_CEI(cl), pspriv, psenc); + + return err; +} + diff -uNrBw libc.orig/citrus/citrus_none.c libc/citrus/citrus_none.c --- libc.orig/citrus/citrus_none.c 2008-06-15 01:01:07.000000000 +0900 +++ libc/citrus/citrus_none.c 2010-11-20 23:00:23.000000000 +0900 @@ -337,6 +337,87 @@ return (0); } +static int +/*ARGSUSED*/ +_citrus_NONE_ctype_mbsnrtowcs(_citrus_ctype_rec_t * __restrict cc, + wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + const char *s; + + /* cc may be unused */ + /* dst may be null */ + _DIAGASSERT(src != NULL && *src != NULL); + /* pspriv may be unused */ + _DIAGASSERT(nresult != NULL); + + if (dst == NULL) { + *nresult = strnlen(*src, slen); + } else { + s = *src; + while (slen > 0 && dlen > 0) { + *dst = (wchar_t)(unsigned char)*s; + if (*dst == L'\0') + break; + ++s, --slen; + ++dst, --dlen; + } + *nresult = (size_t)(*src - s); + } + return 0; +} + +static int +/*ARGSUSED*/ +_citrus_NONE_ctype_wcsnrtombs(_citrus_ctype_rec_t * __restrict cc, + char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, void * __restrict pspriv, + size_t * __restrict nresult) +{ + const wchar_t *s; + size_t n; + + /* cc may be unused */ + /* dst may be null */ + _DIAGASSERT(src != NULL && *src != NULL); + /* pspriv may be unused */ + _DIAGASSERT(nresult != NULL); + + s = *src; + if (dst == NULL) { + n = (size_t)0; + while (slen > 0) { + if (*s & ~0xFF) + goto ilseq; + ++n; + if (*s == L'\0') + break; + ++s, --slen; + } + *nresult = n; + } else { + n = dlen; + while (n > 0 && slen > 0) { + if (*s & ~0xFF) + goto ilseq; + *dst = (unsigned char)*s; + ++dst, --n; + if (*s == L'\0') + break; + ++s, --slen; + } + *src = s; + *nresult = dlen - n; + } + return 0; +ilseq: + *nresult = (size_t)-1; + return EILSEQ; +} + +/* ---------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------- */ _CITRUS_STDENC_DECLS(NONE); diff -uNrBw libc.orig/citrus/modules/citrus_big5.c libc/citrus/modules/citrus_big5.c --- libc.orig/citrus/modules/citrus_big5.c 2010-11-20 14:43:32.000000000 +0900 +++ libc/citrus/modules/citrus_big5.c 2010-11-20 23:00:23.000000000 +0900 @@ -118,6 +118,8 @@ _BIG5State s_wcrtomb; _BIG5State s_wcsrtombs; _BIG5State s_wctomb; + _BIG5State s_mbsnrtowcs; + _BIG5State s_wcsnrtombs; } states; } _BIG5CTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_dechanyu.c libc/citrus/modules/citrus_dechanyu.c --- libc.orig/citrus/modules/citrus_dechanyu.c 2010-11-20 14:45:04.000000000 +0900 +++ libc/citrus/modules/citrus_dechanyu.c 2010-11-20 23:00:23.000000000 +0900 @@ -74,6 +74,8 @@ _DECHanyuState s_wcrtomb; _DECHanyuState s_wcsrtombs; _DECHanyuState s_wctomb; + _DECHanyuState s_mbsnrtowcs; + _DECHanyuState s_wcsnrtombs; } states; } _DECHanyuCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_euc.c libc/citrus/modules/citrus_euc.c --- libc.orig/citrus/modules/citrus_euc.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_euc.c 2010-11-20 23:00:23.000000000 +0900 @@ -110,6 +110,8 @@ _EUCState s_wcrtomb; _EUCState s_wcsrtombs; _EUCState s_wctomb; + _EUCState s_mbsnrtowcs; + _EUCState s_wcsnrtombs; } states; } _EUCCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_euctw.c libc/citrus/modules/citrus_euctw.c --- libc.orig/citrus/modules/citrus_euctw.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_euctw.c 2010-11-20 23:00:23.000000000 +0900 @@ -101,6 +101,8 @@ _EUCTWState s_wcrtomb; _EUCTWState s_wcsrtombs; _EUCTWState s_wctomb; + _EUCTWState s_mbsnrtowcs; + _EUCTWState s_wcsnrtombs; } states; } _EUCTWCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_gbk2k.c libc/citrus/modules/citrus_gbk2k.c --- libc.orig/citrus/modules/citrus_gbk2k.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_gbk2k.c 2010-11-20 23:00:23.000000000 +0900 @@ -75,6 +75,8 @@ _GBK2KState s_wcrtomb; _GBK2KState s_wcsrtombs; _GBK2KState s_wctomb; + _GBK2KState s_mbsnrtowcs; + _GBK2KState s_wcsnrtombs; } states; } _GBK2KCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_hz.c libc/citrus/modules/citrus_hz.c --- libc.orig/citrus/modules/citrus_hz.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_hz.c 2010-11-20 23:00:23.000000000 +0900 @@ -146,6 +146,8 @@ _HZState s_wcrtomb; _HZState s_wcsrtombs; _HZState s_wctomb; + _HZState s_mbsnrtowcs; + _HZState s_wcsnrtombs; } states; } _HZCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_iso2022.c libc/citrus/modules/citrus_iso2022.c --- libc.orig/citrus/modules/citrus_iso2022.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_iso2022.c 2010-11-20 23:00:23.000000000 +0900 @@ -136,6 +136,8 @@ _ISO2022State s_wcrtomb; _ISO2022State s_wcsrtombs; _ISO2022State s_wctomb; + _ISO2022State s_mbsnrtowcs; + _ISO2022State s_wcsnrtombs; } states; } _ISO2022CTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_johab.c libc/citrus/modules/citrus_johab.c --- libc.orig/citrus/modules/citrus_johab.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_johab.c 2010-11-20 23:00:23.000000000 +0900 @@ -74,6 +74,8 @@ _JOHABState s_wcrtomb; _JOHABState s_wcsrtombs; _JOHABState s_wctomb; + _JOHABState s_mbsnrtowcs; + _JOHABState s_wcsnrtombs; } states; } _JOHABCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_mskanji.c libc/citrus/modules/citrus_mskanji.c --- libc.orig/citrus/modules/citrus_mskanji.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_mskanji.c 2010-11-20 23:00:23.000000000 +0900 @@ -110,6 +110,8 @@ _MSKanjiState s_wcrtomb; _MSKanjiState s_wcsrtombs; _MSKanjiState s_wctomb; + _MSKanjiState s_mbsnrtowcs; + _MSKanjiState s_wcsnrtombs; } states; } _MSKanjiCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_ues.c libc/citrus/modules/citrus_ues.c --- libc.orig/citrus/modules/citrus_ues.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_ues.c 2010-11-20 23:00:23.000000000 +0900 @@ -71,6 +71,8 @@ _UESState s_wcrtomb; _UESState s_wcsrtombs; _UESState s_wctomb; + _UESState s_mbsnrtowcs; + _UESState s_wcsnrtombs; } states; } _UESCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_utf7.c libc/citrus/modules/citrus_utf7.c --- libc.orig/citrus/modules/citrus_utf7.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_utf7.c 2010-11-20 23:00:23.000000000 +0900 @@ -82,6 +82,8 @@ _UTF7State s_wcrtomb; _UTF7State s_wcsrtombs; _UTF7State s_wctomb; + _UTF7State s_mbsnrtowcs; + _UTF7State s_wcsnrtombs; } states; } _UTF7CTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_utf8.c libc/citrus/modules/citrus_utf8.c --- libc.orig/citrus/modules/citrus_utf8.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_utf8.c 2010-11-20 23:00:23.000000000 +0900 @@ -115,6 +115,8 @@ _UTF8State s_wcrtomb; _UTF8State s_wcsrtombs; _UTF8State s_wctomb; + _UTF8State s_mbsnrtowcs; + _UTF8State s_wcsnrtombs; } states; } _UTF8CTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_viqr.c libc/citrus/modules/citrus_viqr.c --- libc.orig/citrus/modules/citrus_viqr.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_viqr.c 2010-11-20 23:00:23.000000000 +0900 @@ -237,6 +237,8 @@ _VIQRState s_wcrtomb; _VIQRState s_wcsrtombs; _VIQRState s_wctomb; + _VIQRState s_mbsnrtowcs; + _VIQRState s_wcsnrtombs; } states; } _VIQRCTypeInfo; diff -uNrBw libc.orig/citrus/modules/citrus_zw.c libc/citrus/modules/citrus_zw.c --- libc.orig/citrus/modules/citrus_zw.c 2010-11-20 13:42:55.000000000 +0900 +++ libc/citrus/modules/citrus_zw.c 2010-11-20 23:00:23.000000000 +0900 @@ -80,6 +80,8 @@ _ZWState s_wcrtomb; _ZWState s_wcsrtombs; _ZWState s_wctomb; + _ZWState s_mbsnrtowcs; + _ZWState s_wcsnrtombs; } states; } _ZWCTypeInfo; diff -uNrBw libc.orig/locale/Makefile.inc libc/locale/Makefile.inc --- libc.orig/locale/Makefile.inc 2010-06-19 22:26:52.000000000 +0900 +++ libc/locale/Makefile.inc 2010-11-20 23:00:23.000000000 +0900 @@ -17,11 +17,12 @@ # we have quirk for libc.a - see the last part of lib/libc/Makefile CPPFLAGS+= -DWITH_RUNE -I${.CURDIR} SRCS+= _wctrans.c _wctype.c rune.c runetable.c \ - multibyte_c90.c multibyte_amd1.c iswctype_mb.c + multibyte_c90.c multibyte_amd1.c multibyte_c1x.c iswctype_mb.c CPPFLAGS.rune.c+= -I${LIBCDIR}/citrus CPPFLAGS.runetable.c+= -I${LIBCDIR}/citrus CPPFLAGS.multibyte_c90.c+= -I${LIBCDIR}/citrus CPPFLAGS.multibyte_amd1.c+= -I${LIBCDIR}/citrus +CPPFLAGS.multibyte_c1x.c+= -I${LIBCDIR}/citrus .else # singlebyte locale - dummy CPPFLAGS+= -UWITH_RUNE diff -uNrBw libc.orig/locale/multibyte_c1x.c libc/locale/multibyte_c1x.c --- libc.orig/locale/multibyte_c1x.c 1970-01-01 09:00:00.000000000 +0900 +++ libc/locale/multibyte_c1x.c 2010-11-20 23:03:17.000000000 +0900 @@ -0,0 +1,94 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c)2010 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#define __SETLOCALE_SOURCE__ +#include +#include +#include +#include + +#include "setlocale_local.h" + +#include "citrus_module.h" +#include "citrus_ctype.h" +#include "runetype_local.h" +#include "multibyte.h" + +#define _RUNE_LOCALE() \ + ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE]) + +#define _CITRUS_CTYPE() \ + (_RUNE_LOCALE()->rl_citrus_ctype) + +size_t +mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src, + size_t slen, size_t dlen, mbstate_t * __restrict ps) +{ + size_t ret; + int err0; + + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_mbsnrtowcs(_ps_to_ctype(ps), + dst, src, slen, dlen, _ps_to_private(ps), &ret); + if (err0) + errno = err0; + + return ret; +} + +size_t +wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, + size_t slen, size_t dlen, mbstate_t * __restrict ps) +{ + size_t ret; + int err0; + + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_wcsnrtombs(_ps_to_ctype(ps), + dst, src, slen, dlen, _ps_to_private(ps), &ret); + if (err0) + errno = err0; + + return ret; +} +