From 1c584f59a55cb440f0487854db33b28a08898f82 Mon Sep 17 00:00:00 2001 From: tjr Date: Wed, 7 Apr 2004 09:55:05 +0000 Subject: Prepare to handle trivial state-dependent encodings. Full support for state-dependent encodings with locking shifts will come later if there is demand for it. --- lib/libc/stdio/vfwprintf.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/libc/stdio/vfwprintf.c') diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c index ef7dc30..9a34ff0 100644 --- a/lib/libc/stdio/vfwprintf.c +++ b/lib/libc/stdio/vfwprintf.c @@ -164,6 +164,8 @@ __sbprintf(FILE *fp, const wchar_t *fmt, va_list ap) static wint_t __xfputwc(wchar_t wc, FILE *fp) { + static const mbstate_t initial; + mbstate_t mbs; char buf[MB_LEN_MAX]; struct __suio uio; struct __siov iov; @@ -172,7 +174,8 @@ __xfputwc(wchar_t wc, FILE *fp) if ((fp->_flags & __SSTR) == 0) return (__fputwc(wc, fp)); - if ((len = wcrtomb(buf, wc, NULL)) == (size_t)-1) { + mbs = initial; + if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); } @@ -354,6 +357,8 @@ __ujtoa(uintmax_t val, wchar_t *endp, int base, int octzero, static wchar_t * __mbsconv(char *mbsarg, int prec) { + static const mbstate_t initial; + mbstate_t mbs; wchar_t *convbuf, *wcp; const char *p; size_t insize, nchars, nconv; @@ -372,8 +377,9 @@ __mbsconv(char *mbsarg, int prec) */ p = mbsarg; insize = nchars = 0; + mbs = initial; while (nchars != (size_t)prec) { - nconv = mbrlen(p, MB_CUR_MAX, NULL); + nconv = mbrlen(p, MB_CUR_MAX, &mbs); if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) break; @@ -396,8 +402,9 @@ __mbsconv(char *mbsarg, int prec) return (NULL); wcp = convbuf; p = mbsarg; + mbs = initial; while (insize != 0) { - nconv = mbrtowc(wcp, p, insize, NULL); + nconv = mbrtowc(wcp, p, insize, &mbs); if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) break; wcp++; -- cgit v1.1