make fgetwc set error indicator for stream on encoding errors

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.
This commit is contained in:
Rich Felker 2019-05-05 22:50:57 -04:00
parent d02e72ad51
commit 511d70738b
1 changed files with 8 additions and 2 deletions

View File

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