public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/5994] New: fflush after ungetc on seekable input stream
@ 2008-03-29  5:43 ebb9 at byu dot net
  2008-03-29 16:37 ` [Bug libc/5994] " drepper at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: ebb9 at byu dot net @ 2008-03-29  5:43 UTC (permalink / raw)
  To: glibc-bugs

Consider this program:

$ cat foo.c
#include <stdio.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
  /* Check that fflush after a non-backup ungetc() call discards the ungetc
     buffer.  */
  int c;

  c = fgetc (stdin);
  printf ("c = '%c'\n", c);

  c = fgetc (stdin);
  printf ("c = '%c'\n", c);

  c = ungetc (argc > 1 ? c : '@', stdin);
  printf ("ungetc result = '%c'\n", c);

  fflush (stdin);
  printf ("after fflush, location = %d\n",
	  (int) lseek (fileno (stdin), 0, SEEK_CUR));

  c = fgetc (stdin);
  printf ("c = '%c'\n", c);

  c = fgetc (stdin);
  printf ("c = '%c'\n", c);

  return 0;
}
$ ./foo < foo.c
c = '#'
c = 'i'
ungetc result = '@'
after fflush, location = 582
c = 'n'
c = 'c'
$ ./foo 1 < foo.c
c = '#'
c = 'i'
ungetc result = 'i'
after fflush, location = 1
c = 'i'
c = 'n'


I found it inconsistent that fflush on seekable input streams sets the position
of the underlying file descriptor to a different location based on whether the
byte that was pushed back was what was originally read.  And I'm not the only
one - the Austin Group admitted that Interp-002 is fishy, and that an aardvark
will be needed after POSIX 200x is released to require that fflush discards all
ungetc data and sets the offset of the file descriptor to the stream position
(ie. like the 2nd run, when pushing back the byte that was read, and NOT like
the behavior of the 1st run when pushing back random bytes).

https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=index.tpl&source=L&listname=austin-group-l&id=11398

-- 
           Summary: fflush after ungetc on seekable input stream
           Product: glibc
           Version: 2.3.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: ebb9 at byu dot net
                CC: glibc-bugs at sources dot redhat dot com


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

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libc/5994] fflush after ungetc on seekable input stream
  2008-03-29  5:43 [Bug libc/5994] New: fflush after ungetc on seekable input stream ebb9 at byu dot net
@ 2008-03-29 16:37 ` drepper at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: drepper at redhat dot com @ 2008-03-29 16:37 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2008-03-29 16:37 -------
I'm not even going to look at this until something at the standard level is decided.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED


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

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-03-29 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-29  5:43 [Bug libc/5994] New: fflush after ungetc on seekable input stream ebb9 at byu dot net
2008-03-29 16:37 ` [Bug libc/5994] " drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).