On Sun, Nov 19, 2017 at 08:48:53PM -0500, Rich Felker wrote: > On Sat, Nov 18, 2017 at 05:51:48PM +0100, Szabolcs Nagy wrote: > > Update the buffer position according to the bytes consumed into st when > > decoding an incomplete character at the end of the buffer. > > Further related problems: > > 1. fgetws is unable to accurately determine whether fgetwc failed due > to hitting EOF on a clean stream vs hitting EOF in the middle of a > truncated character. The latter is an EILSEQ condition and should > cause fgetws to return a null pointer rather than a line not ending > in newline. > > 2. fgetwc attempts to leave all but the first byte unread on EILSEQ so > that calling fgetwc again will resync, but doesn't do this > consistently when it has to call getc_unlocked to get new bytes > rather than reading from the buffer. > > I think (1) can be fixed in an ugly way by setting errno to something > other than EILSEQ before calling fgetwc, then checking if EILSEQ upon > failure. Patching this; here's a test case (attached). Rich