Index: citrus/citrus_ctype_template.h =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/citrus_ctype_template.h,v retrieving revision 1.35 diff -u -r1.35 citrus_ctype_template.h --- citrus/citrus_ctype_template.h 9 Feb 2008 14:56:20 -0000 1.35 +++ citrus/citrus_ctype_template.h 23 Nov 2010 12:36:58 -0000 @@ -450,12 +450,11 @@ ei = _CEI_TO_EI(_TO_CEI(cl)); _RESTART_BEGIN(mbrlen, _TO_CEI(cl), pspriv, psenc); if (s == NULL) { - _FUNCNAME(init_state)(ei, psenc); - *nresult = 0; - } else { - err = _FUNCNAME(mbrtowc_priv)(ei, NULL, (const char **)&s, n, - (void *)psenc, nresult); + s = ""; + n = (size_t)1; } + err = _FUNCNAME(mbrtowc_priv)(ei, NULL, (const char **)&s, n, + (void *)psenc, nresult); _RESTART_END(mbrlen, _TO_CEI(cl), pspriv, psenc); return (err); @@ -475,12 +474,11 @@ ei = _CEI_TO_EI(_TO_CEI(cl)); _RESTART_BEGIN(mbrtowc, _TO_CEI(cl), pspriv, psenc); if (s == NULL) { - _FUNCNAME(init_state)(ei, psenc); - *nresult = 0; - } else { - err = _FUNCNAME(mbrtowc_priv)(ei, pwc, (const char **)&s, n, - (void *)psenc, nresult); + s = ""; + n = (size_t)1; } + err = _FUNCNAME(mbrtowc_priv)(ei, pwc, (const char **)&s, n, + (void *)psenc, nresult); _RESTART_END(mbrtowc, _TO_CEI(cl), pspriv, psenc); return (err); @@ -573,9 +571,6 @@ char buf[MB_LEN_MAX]; int err = 0; size_t sz; -#if _ENCODING_IS_STATE_DEPENDENT - size_t rsz = 0; -#endif _DIAGASSERT(cl != NULL); @@ -589,26 +584,8 @@ _RESTART_BEGIN(wcrtomb, _TO_CEI(cl), pspriv, psenc); sz = _ENCODING_MB_CUR_MAX(_CEI_TO_EI(_TO_CEI(cl))); -#if _ENCODING_IS_STATE_DEPENDENT - if (wc == L'\0') { - /* reset state */ - err = _FUNCNAME(put_state_reset)(_CEI_TO_EI(_TO_CEI(cl)), s, - sz, psenc, &rsz); - if (err) { - *nresult = -1; - goto quit; - } - s += rsz; - sz -= rsz; - } -#endif err = _FUNCNAME(wcrtomb_priv)(_CEI_TO_EI(_TO_CEI(cl)), s, sz, wc, psenc, nresult); -#if _ENCODING_IS_STATE_DEPENDENT - if (err == 0) - *nresult += rsz; -quit: -#endif if (err == E2BIG) err = EINVAL; _RESTART_END(wcrtomb, _TO_CEI(cl), pspriv, psenc); @@ -664,9 +641,6 @@ _ENCODING_STATE *psenc; _ENCODING_INFO *ei; size_t nr, sz; -#if _ENCODING_IS_STATE_DEPENDENT - size_t rsz = 0; -#endif int err = 0; _DIAGASSERT(cl != NULL); @@ -681,25 +655,7 @@ return 0; } sz = _ENCODING_MB_CUR_MAX(_CEI_TO_EI(_TO_CEI(cl))); -#if _ENCODING_IS_STATE_DEPENDENT - if (wc == L'\0') { - /* reset state */ - err = _FUNCNAME(put_state_reset)(_CEI_TO_EI(_TO_CEI(cl)), s, - sz, psenc, &rsz); - if (err) { - *nresult = -1; /* XXX */ - return 0; - } - s += rsz; - sz -= rsz; - } -#endif err = _FUNCNAME(wcrtomb_priv)(ei, s, sz, wc, psenc, &nr); -#if _ENCODING_IS_STATE_DEPENDENT - if (err == 0) - *nresult = (int)(nr + rsz); - else -#endif *nresult = (int)nr; return 0; Index: citrus/modules/citrus_big5.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_big5.c,v retrieving revision 1.12 diff -u -r1.12 citrus_big5.c --- citrus/modules/citrus_big5.c 14 Jun 2008 16:01:07 -0000 1.12 +++ citrus/modules/citrus_big5.c 23 Nov 2010 12:36:58 -0000 @@ -304,19 +304,14 @@ int chlenbak; const char *s0; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); - _DIAGASSERT(psenc != NULL); + /* pwc may be null */ _DIAGASSERT(s != NULL && *s != NULL); + _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - _citrus_BIG5_init_state(ei, psenc); - *nresult = 0; - return (0); - } - chlenbak = psenc->chlen; /* make sure we have the first byte in the buffer */ @@ -396,8 +391,9 @@ int l, ret; _DIAGASSERT(ei != NULL); - _DIAGASSERT(nresult != 0); _DIAGASSERT(s != NULL); + /* psenc may be unused */ + _DIAGASSERT(nresult != 0); /* check invalid sequence */ if (wc & ~0xffff || Index: citrus/modules/citrus_dechanyu.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_dechanyu.c,v retrieving revision 1.3 diff -u -r1.3 citrus_dechanyu.c --- citrus/modules/citrus_dechanyu.c 14 Jun 2008 16:01:07 -0000 1.3 +++ citrus/modules/citrus_dechanyu.c 23 Nov 2010 12:36:58 -0000 @@ -191,15 +191,11 @@ wchar_t wc; /* ei may be unused */ - _DIAGASSERT(s != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_DECHanyu_init_state(ei, psenc); - *nresult = _ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; wc = (wchar_t)0; Index: citrus/modules/citrus_euc.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_euc.c,v retrieving revision 1.14 diff -u -r1.14 citrus_euc.c --- citrus/modules/citrus_euc.c 11 Jan 2009 02:46:24 -0000 1.14 +++ citrus/modules/citrus_euc.c 23 Nov 2010 12:36:58 -0000 @@ -209,19 +209,14 @@ int chlenbak; const char *s0, *s1 = NULL; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); - _DIAGASSERT(s != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - _citrus_EUC_init_state(ei, psenc); - *nresult = 0; /* state independent */ - return (0); - } - chlenbak = psenc->chlen; /* make sure we have the first byte in the buffer */ @@ -304,8 +299,9 @@ int cs, i, ret; _DIAGASSERT(ei != NULL); - _DIAGASSERT(nresult != 0); _DIAGASSERT(s != NULL); + /* psenc may be unused */ + _DIAGASSERT(nresult != 0); m = wc & ei->mask; nm = wc & ~m; Index: citrus/modules/citrus_euctw.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_euctw.c,v retrieving revision 1.11 diff -u -r1.11 citrus_euctw.c --- citrus/modules/citrus_euctw.c 14 Jun 2008 16:01:07 -0000 1.11 +++ citrus/modules/citrus_euctw.c 23 Nov 2010 12:36:58 -0000 @@ -200,19 +200,14 @@ int chlenbak; const char *s0; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); - _DIAGASSERT(s != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - _citrus_EUCTW_init_state(ei, psenc); - *nresult = 0; /* state independent */ - return (0); - } - chlenbak = psenc->chlen; /* make sure we have the first byte in the buffer */ @@ -303,8 +298,9 @@ int i, len, clen, ret; _DIAGASSERT(ei != NULL); - _DIAGASSERT(nresult != 0); _DIAGASSERT(s != NULL); + /* psenc may be unused */ + _DIAGASSERT(nresult != 0); clen = 1; if (wc & 0x00007f00) Index: citrus/modules/citrus_gbk2k.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_gbk2k.c,v retrieving revision 1.7 diff -u -r1.7 citrus_gbk2k.c --- citrus/modules/citrus_gbk2k.c 14 Jun 2008 16:01:07 -0000 1.7 +++ citrus/modules/citrus_gbk2k.c 23 Nov 2010 12:36:59 -0000 @@ -171,19 +171,13 @@ wchar_t wc; _DIAGASSERT(ei != NULL); - /* pwc may be NULL */ - _DIAGASSERT(s != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - /* _citrus_GBK2K_init_state(ei, psenc); */ - psenc->chlen = 0; - *nresult = 0; - return (0); - } - chlenbak = psenc->chlen; switch (psenc->chlen) { @@ -277,6 +271,7 @@ _DIAGASSERT(ei != NULL); _DIAGASSERT(s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); if (psenc->chlen != 0) { ret = EINVAL; Index: citrus/modules/citrus_hz.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_hz.c,v retrieving revision 1.2 diff -u -r1.2 citrus_hz.c --- citrus/modules/citrus_hz.c 14 Jun 2008 16:01:07 -0000 1.2 +++ citrus/modules/citrus_hz.c 23 Nov 2010 12:36:59 -0000 @@ -209,16 +209,12 @@ _DIAGASSERT(ei != NULL); /* pwc may be null */ - _DIAGASSERT(s != NULL); + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_HZ_init_state(ei, psenc); - *nresult = 1; - return 0; - } s0 = *s; + if (psenc->chlen < 0 || psenc->inuse == NULL) return EINVAL; Index: citrus/modules/citrus_iso2022.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_iso2022.c,v retrieving revision 1.19 diff -u -r1.19 citrus_iso2022.c --- citrus/modules/citrus_iso2022.c 14 Jun 2008 16:01:07 -0000 1.19 +++ citrus/modules/citrus_iso2022.c 23 Nov 2010 12:36:59 -0000 @@ -852,16 +852,12 @@ int c; int chlenbak; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL || *s != NULL); _DIAGASSERT(psenc != NULL); - _DIAGASSERT(s != NULL); + _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_ISO2022_init_state(ei, psenc); - *nresult = _ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; c = 0; chlenbak = psenc->chlen; @@ -1243,7 +1239,7 @@ _DIAGASSERT(ei != NULL); _DIAGASSERT(s != NULL); _DIAGASSERT(psenc != NULL); - _DIAGASSERT(nresult != 0); + _DIAGASSERT(nresult != NULL); /* XXX state will be modified after this operation... */ ret = _ISO2022_sputwchar(ei, wc, buf, sizeof(buf), &result, psenc, Index: citrus/modules/citrus_johab.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_johab.c,v retrieving revision 1.4 diff -u -r1.4 citrus_johab.c --- citrus/modules/citrus_johab.c 14 Jun 2008 16:01:07 -0000 1.4 +++ citrus/modules/citrus_johab.c 23 Nov 2010 12:36:59 -0000 @@ -174,15 +174,11 @@ int l, t; /* ei may be unused */ - _DIAGASSERT(s != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != 0); - if (*s == NULL) { - _citrus_JOHAB_init_state(ei, psenc); - *nresult = _ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; switch (psenc->chlen) { Index: citrus/modules/citrus_mskanji.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_mskanji.c,v retrieving revision 1.13 diff -u -r1.13 citrus_mskanji.c --- citrus/modules/citrus_mskanji.c 14 Jun 2008 16:01:08 -0000 1.13 +++ citrus/modules/citrus_mskanji.c 23 Nov 2010 12:36:59 -0000 @@ -184,19 +184,14 @@ int chlenbak; const char *s0; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); - _DIAGASSERT(s != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != 0); s0 = *s; - if (s0 == NULL) { - _citrus_MSKanji_init_state(ei, psenc); - *nresult = 0; /* state independent */ - return (0); - } - chlenbak = psenc->chlen; /* make sure we have the first byte in the buffer */ @@ -273,8 +268,9 @@ int ret; _DIAGASSERT(ei != NULL); - _DIAGASSERT(psenc != NULL); _DIAGASSERT(s != NULL); + _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); /* check invalid sequence */ if (wc & ~0xffff) { Index: citrus/modules/citrus_ues.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_ues.c,v retrieving revision 1.1 diff -u -r1.1 citrus_ues.c --- citrus/modules/citrus_ues.c 13 Nov 2006 15:16:31 -0000 1.1 +++ citrus/modules/citrus_ues.c 23 Nov 2010 12:36:59 -0000 @@ -217,15 +217,10 @@ _DIAGASSERT(ei != NULL); /* pwc may be null */ - _DIAGASSERT(s != NULL); + _DIAGASSERT(s != NULL || *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_UES_init_state(ei, psenc); - *nresult = 0; - return 0; - } s0 = *s; hi = (wchar_t)0; @@ -330,6 +325,11 @@ { wchar_t hi, lo; + _DIAGASSERT(ei != NULL); + _DIAGASSERT(s != NULL); + _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); + if (psenc->chlen != 0) return EINVAL; Index: citrus/modules/citrus_utf1632.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_utf1632.c,v retrieving revision 1.11 diff -u -r1.11 citrus_utf1632.c --- citrus/modules/citrus_utf1632.c 20 Mar 2010 18:15:32 -0000 1.11 +++ citrus/modules/citrus_utf1632.c 23 Nov 2010 12:36:59 -0000 @@ -97,19 +97,14 @@ size_t result; const char *s0; - _DIAGASSERT(nresult != 0); _DIAGASSERT(ei != NULL); - _DIAGASSERT(s != NULL); + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - _citrus_UTF1632_init_state(ei, psenc); - *nresult = 0; /* state independent */ - return (0); - } - result = 0; chlenbak = psenc->chlen; @@ -263,8 +258,9 @@ size_t cnt; _DIAGASSERT(ei != NULL); - _DIAGASSERT(nresult != 0); _DIAGASSERT(s != NULL); + _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); cnt = (size_t)0; if (psenc->current_endian == _ENDIAN_UNKNOWN) { Index: citrus/modules/citrus_utf7.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_utf7.c,v retrieving revision 1.5 diff -u -r1.5 citrus_utf7.c --- citrus/modules/citrus_utf7.c 23 Aug 2006 12:57:24 -0000 1.5 +++ citrus/modules/citrus_utf7.c 23 Nov 2010 12:36:59 -0000 @@ -183,6 +183,7 @@ int i, done, len; _DIAGASSERT(ei != NULL); + /* pwc may be null */ _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); @@ -282,12 +283,8 @@ /* pwc may be null */ _DIAGASSERT(s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_UTF7_init_state(ei, psenc); - *nresult = (size_t)_ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; if (psenc->surrogate) { hi = (psenc->cache >> 2) & UTF16_MAX; Index: citrus/modules/citrus_utf8.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_utf8.c,v retrieving revision 1.17 diff -u -r1.17 citrus_utf8.c --- citrus/modules/citrus_utf8.c 14 Jun 2008 16:01:08 -0000 1.17 +++ citrus/modules/citrus_utf8.c 23 Nov 2010 12:37:00 -0000 @@ -100,6 +100,7 @@ } _UTF8State; typedef struct { + int dummy; } _UTF8EncodingInfo; typedef struct { @@ -203,18 +204,14 @@ int c; int i; - _DIAGASSERT(nresult != 0); - _DIAGASSERT(s != NULL); + /* ei may be unused */ + /* pwc may be null */ + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); + _DIAGASSERT(nresult != NULL); s0 = *s; - if (s0 == NULL) { - _citrus_UTF8_init_state(ei, psenc); - *nresult = 0; /* state independent */ - return 0; - } - /* make sure we have the first byte in the buffer */ if (psenc->chlen == 0) { if (n-- < 1) @@ -269,8 +266,10 @@ int cnt, i, ret; wchar_t c; - _DIAGASSERT(nresult != 0); + /* ei may be unused */ _DIAGASSERT(s != NULL); + /* psenc may unused */ + _DIAGASSERT(nresult != NULL); if (_UTF8_surrogate(wc)) { ret = EILSEQ; Index: citrus/modules/citrus_viqr.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_viqr.c,v retrieving revision 1.4 diff -u -r1.4 citrus_viqr.c --- citrus/modules/citrus_viqr.c 14 Jun 2008 16:01:08 -0000 1.4 +++ citrus/modules/citrus_viqr.c 23 Nov 2010 12:37:00 -0000 @@ -299,15 +299,10 @@ _DIAGASSERT(ei != NULL); /* pwc may be null */ - _DIAGASSERT(s != NULL); + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_VIQR_init_state(ei, psenc); - *nresult = (size_t)_ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; i = 0; Index: citrus/modules/citrus_zw.c =================================================================== RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_zw.c,v retrieving revision 1.4 diff -u -r1.4 citrus_zw.c --- citrus/modules/citrus_zw.c 14 Jun 2008 16:01:08 -0000 1.4 +++ citrus/modules/citrus_zw.c 23 Nov 2010 12:37:00 -0000 @@ -141,15 +141,10 @@ /* ei may be unused */ /* pwc may be null */ - _DIAGASSERT(s != NULL); + _DIAGASSERT(s != NULL && *s != NULL); _DIAGASSERT(psenc != NULL); _DIAGASSERT(nresult != NULL); - if (*s == NULL) { - _citrus_ZW_init_state(ei, psenc); - *nresult = (size_t)_ENCODING_IS_STATE_DEPENDENT; - return 0; - } s0 = *s; len = 0; Index: locale/multibyte.h =================================================================== RCS file: /cvsroot/src/lib/libc/locale/multibyte.h,v retrieving revision 1.5 diff -u -r1.5 multibyte.h --- locale/multibyte.h 11 Jan 2009 02:46:28 -0000 1.5 +++ locale/multibyte.h 23 Nov 2010 12:37:00 -0000 @@ -29,6 +29,8 @@ #ifndef _MULTIBYTE_H_ #define _MULTIBYTE_H_ +#include + /* mbstate_t private */ #ifdef _BSD_MBSTATE_T_ @@ -106,21 +108,27 @@ static __inline void _init_ps(_RuneLocale *rl, mbstate_t *ps) { - size_t dum; + void *pspriv; _ps_to_runestate(ps)->rs_runelocale = rl; - _citrus_ctype_mbrtowc(rl->rl_citrus_ctype, NULL, NULL, 0, - _ps_to_private(ps), &dum); + pspriv = _ps_to_private(ps); + memset(pspriv, 0, _PRIVSIZE); } -static __inline void -_fixup_ps(_RuneLocale *rl, mbstate_t *ps, int forceinit) +static __inline int +_fixup_ps(_RuneLocale *rl, mbstate_t *ps) { + _RuneLocale *cur; /* for future multi-locale facility */ _DIAGASSERT(rl != NULL); - if (ps != NULL && (_ps_to_runelocale(ps) == NULL || forceinit)) { - _init_ps(rl, ps); + if (ps != NULL) { + cur = _ps_to_runelocale(ps); + if (cur == NULL) + _init_ps(rl, ps); + else if (cur != rl) + return EINVAL; } + return 0; } #endif /*_MULTIBYTE_H_*/ Index: locale/multibyte_amd1.c =================================================================== RCS file: /cvsroot/src/lib/libc/locale/multibyte_amd1.c,v retrieving revision 1.9 diff -u -r1.9 multibyte_amd1.c --- locale/multibyte_amd1.c 13 Jun 2010 04:14:57 -0000 1.9 +++ locale/multibyte_amd1.c 23 Nov 2010 12:37:00 -0000 @@ -37,6 +37,8 @@ #include #define __SETLOCALE_SOURCE__ #include +#include +#include #include #include "setlocale_local.h" @@ -58,10 +60,12 @@ size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); - - err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n, - _ps_to_private(ps), &ret); + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), + s, n, _ps_to_private(ps), &ret); if (err0) errno = err0; @@ -72,22 +76,19 @@ mbsinit(const mbstate_t *ps) { int ret; - int err0; _RuneLocale *rl; if (ps == NULL) return 1; + rl = _ps_to_runelocale(ps); + if (rl == NULL) + return 1; - if (_ps_to_runelocale(ps) == NULL) - rl = _RUNE_LOCALE(); - else - rl = _ps_to_runelocale(ps); + if (rl != _RUNE_LOCALE()) + return 0; - /* mbsinit should cause no error... */ - err0 = _citrus_ctype_mbsinit(rl->rl_citrus_ctype, - _ps_to_private_const(ps), &ret); - if (err0) - errno = err0; + (void)_citrus_ctype_mbsinit(rl->rl_citrus_ctype, + _ps_to_private_const(ps), &ret); return ret; } @@ -98,10 +99,12 @@ size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); - - err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n, - _ps_to_private(ps), &ret); + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), + pwc, s, n, _ps_to_private(ps), &ret); if (err0) errno = err0; @@ -114,10 +117,12 @@ size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); - - err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n, - _ps_to_private(ps), &ret); + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), + pwcs, s, n, _ps_to_private(ps), &ret); if (err0) errno = err0; @@ -130,10 +135,12 @@ size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); - - err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc, - _ps_to_private(ps), &ret); + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), + s, wc, _ps_to_private(ps), &ret); if (err0) errno = err0; @@ -146,10 +153,12 @@ size_t ret; int err0; - _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); - - err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n, - _ps_to_private(ps), &ret); + err0 = _fixup_ps(_RUNE_LOCALE(), ps); + if (err0) + ret = (size_t)-1; + else + err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), + s, ppwcs, n, _ps_to_private(ps), &ret); if (err0) errno = err0;