Mail Archives: cygwin/2004/04/23/04:19:51
Quick update: The same testcase, compiled under MSYS 1.0.10 with Mingw
gcc (gcc 3.2.3 (mingw special 20030504-1)), does not exhibit the problem
No.1, but still shows the No.2 when run in a standard DOS box. When run
inside a MSYS window it does not recognize as EOF either Ctrl-Z or Ctrl-D,
so the test No.2 can't take place...
Enzo
----- Original Message -----
From: "Enzo Michelangeli" <em AT em DOT no-ip DOT com>
To: <cygwin AT cygwin DOT com>
Sent: Friday, April 23, 2004 10:32 AM
Subject: Re: 1.5.9-1: weird console I/O behaviour compiling
with -mno-cygwin
Hello,
Please consider the following testcase:
------ begin weirdio.c -------
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int rc;
char buf[1024];
char *s = "read() done\n";
for(rc=1;rc>0;) {
rc = read(0, buf, sizeof(buf) - 1);
// sleep(0); temporarily uncommented
write(1, s, (size_t)strlen(s));
}
}
------- end weirdio.c -------
when compiled with "gcc -o weirdio weirdio.c" it behaves as expected:
-----------------------------
em AT emnb ~/weirdio
$ ./weirdio
$ ./weirdio
aaa <--- "Return" key hit on the keyboard
read() done
aaa <--- "Return" key hit on the keyboard
read() done
bbb <--- "Return" key hit on the keyboard
read() done <--- EOF (Ctrl-D) hit on the keyboard
read() done <--- last write() duly executed
em AT emnb ~/weirdio
$
-----------------------------
However, compiling with "gcc -mno-cygwin -o weirdio weirdio.c" two strange
things happen:
1. Only when executed inside a cygwin window (at the bash prompt), the
first time "read()" returns as if someone had hit the "Return" key
(further investigation with gdb revealed that read() returned 1 and placed
one \n character in the buffer).
2. Either at the bash prompt, or in a plain DOS window (under Win98SE) the
last "read() done" after EOF (which now is Ctrl-Z) is NOT printed. BUT, it
is duly printed if the "sleep(0)" (or sleep with any other argument) is
uncommented!
Unfortunately, I have no MSVC++ compiler, so I can't see what happens
compiling with the tools of the Evil Empire.
Any idea?
Enzo
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -