[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fflush after ungetc
From: |
Bruno Haible |
Subject: |
Re: fflush after ungetc |
Date: |
Thu, 6 Mar 2008 23:46:34 +0100 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote on Saturday:
> Newlib has two bugs - first, fflush is failing to discard ungetc data when
> changing the underlying fd offset.
Do you know the wording that the newest POSIX has about this?
The following test program, run on various platforms, gives unconclusive
results.
========================== foo.c =========================
#include <stdio.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 ('@', stdin);
printf ("ungetc result = '%c'\n", c);
fflush (stdin);
c = fgetc (stdin);
printf ("c = '%c'\n", c);
c = fgetc (stdin);
printf ("c = '%c'\n", c);
return 0;
}
=============================================================
$ gcc foo.c
$ ./a.out < foo.c
$ cat foo.c | ./a.out
On glibc-2.3.6: Different results.
When reading from the regular file:
c = '#'
c = 'i'
ungetc result = '@'
c = 'n'
c = 'c'
When reading from the pipe:
c = '#'
c = 'i'
ungetc result = '@'
c = '@'
c = 'n'
On MacOS X: twice
c = '#'
c = 'i'
ungetc result = '@'
c = '@'
c = 'n'
On HP-UX 11:
When reading from the regular file:
c = '#'
c = 'i'
ungetc result = '@'
c = 'i'
c = 'n'
When reading from the pipe:
c = '#'
c = 'i'
ungetc result = '@'
c = <EOF>
c = <EOF>
If I understand the comments in lib/fflush.c right, the second half of my
test is unspecified behaviour, and the first half is specified and exposes
in MacOS X the same bug as on Cygwin?
Bruno
- Re: new module 'freadseek', Eric Blake, 2008/03/01
- Message not available
- Re: fflush after ungetc, Eric Blake, 2008/03/26
- Re: fflush after ungetc, Bruno Haible, 2008/03/06
- Re: fflush after ungetc, Eric Blake, 2008/03/06
- Re: fflush after ungetc, Bruno Haible, 2008/03/09
- Re: fflush after ungetc, Eric Blake, 2008/03/29