diff options
author | ache <ache@FreeBSD.org> | 2016-09-04 00:34:15 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2016-09-04 00:34:15 +0000 |
commit | 1e309d41a8764622d76a93336df84be6bce2da29 (patch) | |
tree | e8a1c3aae37c4871ccb359e524a2a57d240ce863 /lib/libc | |
parent | bcdec745e0ba540a8e558e912b2150c232fb472e (diff) | |
download | FreeBSD-src-1e309d41a8764622d76a93336df84be6bce2da29.zip FreeBSD-src-1e309d41a8764622d76a93336df84be6bce2da29.tar.gz |
MFC r305219
If error happens, don't overwrite original errno comes from __mbrtowc()
and __srefill().
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/fgetwc.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index cf649fd..3074d44 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -84,9 +84,10 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale) return (WEOF); do { nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs); - if (nconv == (size_t)-1) - break; - else if (nconv == (size_t)-2) + if (nconv == (size_t)-1) { + fp->_flags |= __SERR; + return (WEOF); + } else if (nconv == (size_t)-2) continue; else if (nconv == 0) { fp->_p++; @@ -100,7 +101,9 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale) return (wc); } } while (__srefill(fp) == 0); - fp->_flags |= __SERR; - errno = EILSEQ; + if (__sfeof(fp)) { + fp->_flags |= __SERR; + errno = EILSEQ; + } return (WEOF); } |