diff options
| author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-05-22 15:19:41 +0000 |
|---|---|---|
| committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-05-22 15:19:41 +0000 |
| commit | 87275e436a0fb31fea2757532860a3ec993d2cd6 (patch) | |
| tree | f6b3a5846b5b7d1a722dc68d0c48e70c32df2e55 /lib/libc/stdio/fgetwc.c | |
| parent | d0834d4dc80a4f57c5979ccd810fc2e2c204d595 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio/fgetwc.c')
| -rw-r--r-- | lib/libc/stdio/fgetwc.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index 0b8344135e22..4463042295cd 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -77,34 +77,31 @@ fgetwc(FILE *fp) static __inline wint_t __fgetwc_nbf(FILE *fp) { - static const mbstate_t initial; - mbstate_t mbs; - char buf[MB_LEN_MAX]; size_t n, nconv; int c; + char cc; wchar_t wc; n = 0; - while (n < MB_CUR_MAX) { + for (;;) { if ((c = __sgetc(fp)) == EOF) { if (n == 0) return (WEOF); break; } - buf[n++] = (char)c; - mbs = initial; - nconv = mbrtowc(&wc, buf, n, &mbs); - if (nconv == n) - return (wc); - else if (nconv == 0) - return (L'\0'); + n++; + cc = (char)c; + nconv = mbrtowc(&wc, &cc, 1, &fp->_extra->mbstate); + if (nconv == (size_t)-2) + continue; else if (nconv == (size_t)-1) break; + else if (nconv == 0) + return (L'\0'); + else + return (wc); } - - while (n-- != 0) - __ungetc((unsigned char)buf[n], fp); - errno = EILSEQ; fp->_flags |= __SERR; + errno = EILSEQ; return (WEOF); } |
