mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix spurious failures by fgetws when buffer ends with partial character
commita90d9da1d1
made fgetws look for changes to errno by fgetwc to detect encoding errors, since ISO C did not allow the implementation to set the stream's error flag in this case, and the fgetwc interface did not admit any other way to detect the error. however, the possibility of fgetwc setting errno to EILSEQ in the success path was overlooked, and in fact this can happen if the buffer ends with a partial character, causing mbtowc to be called with only part of the character available. since that change was made, the C standard was amended to specify that fgetwc set the stream error flag on encoding errors, and commit511d70738b
made it do so. thus, there is no longer any need for fgetws to poke at errno to handle encoding errors. this commit reverts commita90d9da1d1
and thereby fixes the problem.
This commit is contained in:
parent
5690668a1b
commit
f8bdc30482
1 changed files with 1 additions and 6 deletions
|
@ -1,6 +1,5 @@
|
|||
#include "stdio_impl.h"
|
||||
#include <wchar.h>
|
||||
#include <errno.h>
|
||||
|
||||
wint_t __fgetwc_unlocked(FILE *);
|
||||
|
||||
|
@ -12,10 +11,6 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
|
|||
|
||||
FLOCK(f);
|
||||
|
||||
/* Setup a dummy errno so we can detect EILSEQ. This is
|
||||
* the only way to catch encoding errors in the form of a
|
||||
* partial character just before EOF. */
|
||||
errno = EAGAIN;
|
||||
for (; n; n--) {
|
||||
wint_t c = __fgetwc_unlocked(f);
|
||||
if (c == WEOF) break;
|
||||
|
@ -23,7 +18,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
|
|||
if (c == '\n') break;
|
||||
}
|
||||
*p = 0;
|
||||
if (ferror(f) || errno==EILSEQ) p = s;
|
||||
if (ferror(f)) p = s;
|
||||
|
||||
FUNLOCK(f);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue