diff options
author | ache <ache@FreeBSD.org> | 2016-09-04 00:35:55 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2016-09-04 00:35:55 +0000 |
commit | 095ef2997fdb40de71fe02e24727d5db2c1316f9 (patch) | |
tree | 462da52b3686583e829c84fe6b3227433add0dba /lib/libc | |
parent | 301c0aa62846a9d5f118f4bcece1d73c3dd47cb2 (diff) | |
download | FreeBSD-src-095ef2997fdb40de71fe02e24727d5db2c1316f9.zip FreeBSD-src-095ef2997fdb40de71fe02e24727d5db2c1316f9.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); } |