Bug in Control-d handling?
Ken Brown
kbrown@cornell.edu
Sun Jun 19 19:08:19 GMT 2022
Consider the following program, which reads from standard input a line at a time
and then echoes the input back to the terminal:
$ cat cat_line.c
#include <stdio.h>
int main ()
{
char buf[BUFSIZ];
while (fgets (buf, BUFSIZ, stdin))
fputs (buf, stdout);
}
Run the program, type one or more characters (without hitting Enter), and type
Ctrl-d until the program exits. What I expect is that nothing visible happens
on the first Ctrl-d [but the input is sent to the internal stdin buffer], and
that the input is echoed and the program exits after the second Ctrl-d [the
program sees EOF]. This is what happens on Linux. On Cygwin, however, the
program keeps running after the second Ctrl-d and doesn't exit until Ctrl-d is
pressed a third time.
I observed this problem because of a failing Emacs test, in which the program
"rev" was not seeing EOF after being sent Ctrl-d; "rev" does something like the
test case above, but using fgetws instead of fgets.
Ken
More information about the Cygwin
mailing list