correct the return values of wcrtomb(3) and wctomb(3).

These return values should include the length of shift sequence
to restore the initial shift state.
This commit is contained in:
soda 2004-09-25 22:53:46 +00:00
parent 857913deac
commit bb8f03e106
1 changed files with 12 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_ctype_template.h,v 1.25 2004/01/02 21:49:35 itojun Exp $ */
/* $NetBSD: citrus_ctype_template.h,v 1.26 2004/09/25 22:53:46 soda Exp $ */
/*-
* Copyright (c)2002 Citrus Project,
@ -573,6 +573,9 @@ _FUNCNAME(ctype_wcrtomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
char buf[MB_LEN_MAX];
int err = 0;
size_t sz;
#if _ENCODING_IS_STATE_DEPENDENT
size_t rsz = 0;
#endif
_DIAGASSERT(cl != NULL);
@ -588,7 +591,6 @@ _FUNCNAME(ctype_wcrtomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
sz = _ENCODING_MB_CUR_MAX(_CEI_TO_EI(_TO_CEI(cl)));
#if _ENCODING_IS_STATE_DEPENDENT
if (wc == L'\0') {
size_t rsz;
/* reset state */
err = _FUNCNAME(put_state_reset)(_CEI_TO_EI(_TO_CEI(cl)), s,
sz, psenc, &rsz);
@ -601,6 +603,7 @@ _FUNCNAME(ctype_wcrtomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
err = _FUNCNAME(wcrtomb_priv)(_CEI_TO_EI(_TO_CEI(cl)), s, sz,
wc, psenc, nresult);
#if _ENCODING_IS_STATE_DEPENDENT
*nresult += rsz;
quit:
#endif
if (err == E2BIG)
@ -658,6 +661,9 @@ _FUNCNAME(ctype_wctomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
_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);
@ -674,7 +680,6 @@ _FUNCNAME(ctype_wctomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
sz = _ENCODING_MB_CUR_MAX(_CEI_TO_EI(_TO_CEI(cl)));
#if _ENCODING_IS_STATE_DEPENDENT
if (wc == L'\0') {
size_t rsz;
/* reset state */
err = _FUNCNAME(put_state_reset)(_CEI_TO_EI(_TO_CEI(cl)), s,
sz, psenc, &rsz);
@ -687,7 +692,11 @@ _FUNCNAME(ctype_wctomb)(void * __restrict cl, char * __restrict s, wchar_t wc,
}
#endif
err = _FUNCNAME(wcrtomb_priv)(ei, s, sz, wc, psenc, &nr);
#if _ENCODING_IS_STATE_DEPENDENT
*nresult = (int)(nr + rsz);
#else
*nresult = (int)nr;
#endif
return 0;
}