public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12799] New: fflush violates POSIX on seekable input streams
@ 2011-05-23 17:14 eblake at redhat dot com
  2012-02-21  2:23 ` [Bug stdio/12799] " jsm28 at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: eblake at redhat dot com @ 2011-05-23 17:14 UTC (permalink / raw)
  To: glibc-bugs

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

           Summary: fflush violates POSIX on seekable input streams
           Product: glibc
           Version: 2.13
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: eblake@redhat.com


Per http://austingroupbugs.net/view.php?id=87, fflush is required to discard
any ungetc() bytes and set the underlying file position to the point as though
the pushed-back bytes had never been read.  That is, in the sequence:

{ app1; app2; } < seekable

if app1 reads one byte too many, then does ungetc() to push it back, then app2
should start reading at the byte that app1 did not want, rather than at the
point that app1 reached before using ungetc().  More concretely, this program
should exit with status 0, but right now it is exiting with status 7 (glibc is
reading 'w' instead of ' ' after the fflush):


#define _POSIX_C_SOURCE 200112L
#include <stdio.h>
int main (void)
{
  FILE *f;
  char buffer[10];
  int fd;
  int c;

  f = fopen ("file", "w+");
  if (f == NULL)
    return 1;
  if (fputs ("hello world", f) == EOF)
    return 2;
  rewind (f);

  fd = fileno (f);
  if (fd < 0 || fread (buffer, 1, 5, f) != 5)
    return 3;
  c = fgetc (f);
  if (c != ' ')
    return 4;
  if (ungetc ('@', f) != '@')
    return 5;
  if (fflush (f) == EOF)
    return 6;
  if (fgetc (f) != c)
    return 7;
  return 0;
}

This program returns 0 on Solaris and Cygwin.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2021-01-22  2:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-23 17:14 [Bug libc/12799] New: fflush violates POSIX on seekable input streams eblake at redhat dot com
2012-02-21  2:23 ` [Bug stdio/12799] " jsm28 at gcc dot gnu.org
2012-10-29 14:00 ` siddhesh at redhat dot com
2012-12-11 11:48 ` hannes at stressinduktion dot org
2012-12-19 10:48 ` schwab@linux-m68k.org
2014-06-27 13:17 ` fweimer at redhat dot com
2020-04-14  0:18 ` eblake at redhat dot com
2020-04-14  0:24 ` eblake at redhat dot com
2020-04-14 15:59 ` rjones at redhat dot com
2020-08-02 23:05 ` chimpatheist at gmail dot com
2020-08-03 18:34 ` chimpatheist at gmail dot com
2020-08-03 20:03 ` chimpatheist at gmail dot com
2021-01-22  2:47 ` dancol at dancol dot org

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).