This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fflush(NULL) empties stdin


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

Working through 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

    $ cat a.c
    #include <stdio.h>
    int main(void)
            char buf[256];
            while (fgets(buf, sizeof(buf), stdin)) {
                    fprintf(stdout, "got: %s", buf);
            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

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



Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]