In an decision on 2009-01-08, see <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt>, the Austin group decided about the behaviour of fflush after ungetc. The following wording was adopted: "For a stream open for reading, if the file is not already at EOF, and the file is one capable of seeking, the file offset of the underlying open file description shall be set to the file position of the stream, and any characters pushed back onto the stream by ungetc() or ungetwc() that have not subsequently been read from the stream shall be discarded." In this situation, glibc correctly drops the pushed back characters and correctly keeps the stream's position unchanged, but something inside the stream becomes inconsistent: the next fgetc call returns a wrong result. To reproduce: $ gcc -O -Wall bug.c -o bug $ ./bug < bug.c; echo $? file position before fflush: 1 file position after fflush: 1 character read: ' ' but expected '*' 5 Expected output: file position before fflush: 1 file position after fflush: 1 0
Created attachment 3668 [details] test case
This bug is about the same issue as in 5994. *** This bug has been marked as a duplicate of bug 5994 ***