Author: ache
Date: Thu Sep  1 18:12:53 2016
New Revision: 305219
URL: https://svnweb.freebsd.org/changeset/base/305219

Log:
  If error happens, don't overwrite original errno comes from __mbrtowc()
  and __srefill().
  
  MFC after:      3 days

Modified:
  head/lib/libc/stdio/fgetwc.c

Modified: head/lib/libc/stdio/fgetwc.c
==============================================================================
--- head/lib/libc/stdio/fgetwc.c        Thu Sep  1 18:11:44 2016        
(r305218)
+++ head/lib/libc/stdio/fgetwc.c        Thu Sep  1 18:12:53 2016        
(r305219)
@@ -84,9 +84,10 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, i
                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, i
                        return (wc);
                }
        } while (__srefill(fp) == 0);
-       fp->_flags |= __SERR;
-       errno = EILSEQ;
+       if (__sfeof(fp)) {
+               fp->_flags |= __SERR;
+               errno = EILSEQ;
+       }
        return (WEOF);
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to