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

On 7/18/2017 3:21 PM, Achim Gratz wrote:
Corinna Vinschen writes:
Oh, and a plain C testcase, of course...

Call that fflush.c:

--8<---------------cut here---------------start------------->8---
#include <stdio.h>
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);
         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.

I've checked that the 2017-03-08 snapshot is good and the 2017-03-10 snapshot is bad. I'll bisect further when I get a chance, but maybe that's already enough to pin down the problem.


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