make fgetwc set error indicator for stream on encoding errors
authorRich Felker <dalias@aerifal.cx>
Mon, 6 May 2019 02:50:57 +0000 (22:50 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 6 May 2019 02:50:57 +0000 (22:50 -0400)
this is a requirement in POSIX that's omitted, and seemed potentially
non-conforming, in the C standard. as such it was omitted here.
however, as part of Austin Group issue #1170, the discrepancy was
raised with WG14 and determined to be unintended; future versions of
the C standard will require the error indicator to be set, as POSIX
does.

src/stdio/fgetwc.c

index 0801e28f9de1d5c70bc3c9850bb181e4e395a6d1..aa10b818566a8f1d19af680a9d00458d101572fa 100644 (file)
@@ -25,12 +25,18 @@ static wint_t __fgetwc_unlocked_internal(FILE *f)
        do {
                b = c = getc_unlocked(f);
                if (c < 0) {
-                       if (!first) errno = EILSEQ;
+                       if (!first) {
+                               f->flags |= F_ERR;
+                               errno = EILSEQ;
+                       }
                        return WEOF;
                }
                l = mbrtowc(&wc, (void *)&b, 1, &st);
                if (l == -1) {
-                       if (!first) ungetc(b, f);
+                       if (!first) {
+                               f->flags |= F_ERR;
+                               ungetc(b, f);
+                       }
                        return WEOF;
                }
                first = 0;