This is the mail archive of the cygwin-apps 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]

Re: fflush(NULL) clobbers input streams


Corinna Vinschen writes:
> Oh, and a plain C testcase, of course...

Call that fflush.c:

--8<---------------cut here---------------start------------->8---
#include <stdio.h>
int
main(int argc, char **argv)
{
    char buf[1024];
    int i;
    char *bp = buf;
    while (1) {
        while ((i = getc(stdin)) != -1
               && (*bp++ = i) != '\n'
               && bp < &buf[1024])
        /* DO NOTHING */ ;
        *bp = '\0';
        fprintf(stdout, "%s", buf);
        fflush(NULL);
        if (i == -1)
            return 0;
        bp = buf;
    }
}
--8<---------------cut here---------------end--------------->8---

Then run:

gcc fflush.c -o fflush
cat fflush.c | ./fflush 2>/dev/null > fflush.out
diff fflush.c fflush.out

If things are working, fflush.c and fflush.out should be identical.
Currently only the first line makes it into fflush.out on Cygwin.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds


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