diff options
| author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-18 05:58:11 +0000 |
|---|---|---|
| committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-18 05:58:11 +0000 |
| commit | 24990dfad088db7073e30b8870d62366fb510cd3 (patch) | |
| tree | 89b31678132bc76b873bf1bba095a04aa70ff775 /lib/libc/stdio/ungetwc.c | |
| parent | 11142c6f5488b60ab8109f8a90f2294266758078 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio/ungetwc.c')
| -rw-r--r-- | lib/libc/stdio/ungetwc.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c index 2a509865ffc9..0783fa9d5c91 100644 --- a/lib/libc/stdio/ungetwc.c +++ b/lib/libc/stdio/ungetwc.c @@ -29,8 +29,8 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <errno.h> -#include <rune.h> #include <stdio.h> +#include <stdlib.h> #include <wchar.h> #include "un-namespace.h" #include "libc_private.h" @@ -39,8 +39,21 @@ __FBSDID("$FreeBSD$"); wint_t ungetwc(wint_t wc, FILE *fp) { + char buf[MB_LEN_MAX]; + mbstate_t mbs; + size_t len; ORIENTLOCK(fp, 1); - return (fungetrune((rune_t)wc, fp) == EOF ? WEOF : wc); + if (wc == WEOF) + return (WEOF); + + memset(&mbs, 0, sizeof(mbs)); + if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) + return (WEOF); + while (len-- != 0) + if (ungetc((unsigned char)buf[len], fp) == EOF) + return (WEOF); + + return (wc); } |
