public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* fflush(NULL) empties stdin
@ 2017-08-26 21:52 Adam Dinwoodie
  2017-08-26 23:57 ` Ken Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Dinwoodie @ 2017-08-26 21:52 UTC (permalink / raw)
  To: cygwin

Hello,

I seem to have found a bug in Cygwin's fflush implementation, where
fflush(NULL) is unexpectedly flushing stdin.

Working through https://cygwin.com/snapshots/ with the STC below, this
behaviour does not appear in the 2017-03-08 snapshot, and 2017-03-10 is
the first snapshot in which this does appear, with thanks to Ramsay
Jones on the Git mailing list for initially pointing me at the change
coming in some time between 2.7.0 and 2.8.0.

With thanks to Jeff King on the Git mailing list, here's a simple test
case:

    $ cat a.c
    #include <stdio.h>
    
    int main(void)
    {
            char buf[256];
            while (fgets(buf, sizeof(buf), stdin)) {
                    fprintf(stdout, "got: %s", buf);
                    fflush(NULL);
            }
            return 0;
    }
    
    $ gcc a.c
    
    $ seq 10 | ./a.exe
    got: 1

Compare this to the expected output, which I see on my handy CentOS 6
box:

    $ seq 10 | ./a.out
    got: 1
    got: 2
    got: 3
    got: 4
    got: 5
    got: 6
    got: 7
    got: 8
    got: 9
    got: 10

By my reading of Cygwin's fflush(3p), the stdin stream should be
unaffected by a fflush(NULL), as it is neither an output stream, an
update stream, nor a file capable of seeking.

I originally noticed this behaviour due to it causing a failure in one
of the Git test scripts.

Cheers,

Adam

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2017-08-27 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-26 21:52 fflush(NULL) empties stdin Adam Dinwoodie
2017-08-26 23:57 ` Ken Brown
2017-08-27 11:31   ` Adam Dinwoodie

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