From a27a4b369016302f5feeeceed5a128aedb6bcb1f Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Tue, 4 Nov 2003 11:05:55 +0000 Subject: [PATCH] Pass mbrtowc() and wcrtomb() NULL instead of a pointer to a freshly zeroed mbstate_t object that they ignore. The zeroing is fairly expensive, and it will never be necessary in these functions; when we support state-dependent encodings, we will pass in a pointer to the file's mbstate_t object, and only zero it at the time the file gets opened. --- lib/libc/stdio/fgetwc.c | 4 +--- lib/libc/stdio/fputwc.c | 4 +--- lib/libc/stdio/ungetwc.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index 93438a60035..3a6e6e135e0 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -78,7 +78,6 @@ static __inline wint_t __fgetwc_nbf(FILE *fp) { char buf[MB_LEN_MAX]; - mbstate_t mbs; size_t n, nconv; int c; wchar_t wc; @@ -91,8 +90,7 @@ __fgetwc_nbf(FILE *fp) break; } buf[n++] = (char)c; - memset(&mbs, 0, sizeof(mbs)); - nconv = mbrtowc(&wc, buf, n, &mbs); + nconv = mbrtowc(&wc, buf, n, NULL); if (nconv == n) return (wc); else if (nconv == 0) diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c index ed1f11bbccc..ba3c5bbfdf8 100644 --- a/lib/libc/stdio/fputwc.c +++ b/lib/libc/stdio/fputwc.c @@ -44,7 +44,6 @@ wint_t __fputwc(wchar_t wc, FILE *fp) { char buf[MB_LEN_MAX]; - mbstate_t mbs; size_t i, len; if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { @@ -56,8 +55,7 @@ __fputwc(wchar_t wc, FILE *fp) *buf = (unsigned char)wc; len = 1; } else { - memset(&mbs, 0, sizeof(mbs)); - if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + if ((len = wcrtomb(buf, wc, NULL)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); } diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c index e20a763c47e..c9d5c490b3c 100644 --- a/lib/libc/stdio/ungetwc.c +++ b/lib/libc/stdio/ungetwc.c @@ -43,13 +43,11 @@ wint_t __ungetwc(wint_t wc, FILE *fp) { char buf[MB_LEN_MAX]; - mbstate_t mbs; size_t len; if (wc == WEOF) return (WEOF); - memset(&mbs, 0, sizeof(mbs)); - if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + if ((len = wcrtomb(buf, wc, NULL)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); }