diff options
author | tjr <tjr@FreeBSD.org> | 2004-04-06 13:14:03 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2004-04-06 13:14:03 +0000 |
commit | 4212f9711ffee179c943b9f40b788b759a1ad9e6 (patch) | |
tree | 6779dc19a3df61ca545f851748ebd5f5de3a255e /lib/libc/locale/btowc.c | |
parent | fcc4fa555ff7fcd7b9e4327aa717b090a18361b5 (diff) | |
download | FreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.zip FreeBSD-src-4212f9711ffee179c943b9f40b788b759a1ad9e6.tar.gz |
Prepare to handle state-dependent encodings. This mainly involves not
taking shortcuts when it comes to storing and passing around conversion
states.
Diffstat (limited to 'lib/libc/locale/btowc.c')
-rw-r--r-- | lib/libc/locale/btowc.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/libc/locale/btowc.c b/lib/libc/locale/btowc.c index b0b24f2..34439b8 100644 --- a/lib/libc/locale/btowc.c +++ b/lib/libc/locale/btowc.c @@ -28,28 +28,25 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> -#include <string.h> #include <wchar.h> wint_t btowc(int c) { + static const mbstate_t initial; + mbstate_t mbs = initial; char cc; wchar_t wc; if (c == EOF) return (WEOF); - cc = (char)c; /* * We expect mbrtowc() to return 0 or 1, hence the check for n > 1 * which detects error return values as well as "impossible" byte * counts. - * - * We pass NULL as the state pointer to mbrtowc() because we don't - * support state-dependent encodings and don't want to waste time - * creating a zeroed mbstate_t that will not be used. */ - if (mbrtowc(&wc, &cc, 1, NULL) > 1) + cc = (char)c; + if (mbrtowc(&wc, &cc, 1, &mbs) > 1) return (WEOF); return (wc); } |