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