This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/9754] New: fflush after ungetc not POSIX compliant


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

-- 
           Summary: fflush after ungetc not POSIX compliant
           Product: glibc
           Version: 2.8
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: bruno at clisp dot org
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


http://sourceware.org/bugzilla/show_bug.cgi?id=9754

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]