Mail Archives: cygwin/1998/02/28/08:31:56
Hello,
I decided to give B19 a try and came across a problem. Attached is a
short
program that demonstrates it.
Basically, I set stdin to O_NONBLOCK, do an fgets and the result is
missing
the first character. It looks pretty straightforward but then I may be
seeing things.
My tests with B18 indicate that O_NONBLOCK did not work.
The sample could probably be simplified further, it is an extract from a
real
program. Some of the printing was added during the testing.
/* tt.c
*
* Demonstrate a problem with Cygnus Win32 b19.
*
* build as 'gcc -o tt tt.c'
* run as 'tt'. Observe that when you type a string, the first character
* is not echoed, and is not in the result either.
*
* With B18 the string was read properly but stdin remained blocking
* after the O_NONBLOCK fcntl.
*
* You lose on the swings...
*
* Date: 28 Feb 98
* From: Eyal Lebedinsky <eyal AT eyal DOT emu DOT id DOT au>
*/
#include <stdio.h>
#include <unistd.h> /* STDIN_FILENO */
#include <fcntl.h> /* fcntl, F_SETFL, F_GETFL, O_NONBLOCK */
#include <errno.h> /* errno */
static char msg[1500]; /* message buffer */
int
main ()
{
int ret;
ret = fcntl (STDIN_FILENO, F_GETFL, 0);
if (fcntl (STDIN_FILENO, F_SETFL, ret | O_NONBLOCK) < 0) {
printf ("fcntl(stdin) failed: %s\n",
strerror (errno));
exit (1);
}
for (;;) {
msg[0] = '\0';
if (NULL == fgets (msg, sizeof(msg), stdin)) {
if (EWOULDBLOCK == errno) {
if (msg[0] != '\0') /* any strays?
*/
printf ("[%s]", msg);
continue;
}
printf ("user input failed, exiting\n");
break;
}
printf ("\ngot len=%d '%s'\n", strlen (msg), msg);
if (!strcmp ("end\n", msg))
break;
}
ret = fcntl (STDIN_FILENO, F_GETFL, 0);
fcntl (STDIN_FILENO, F_SETFL, ret & ~O_NONBLOCK);
return (0);
}
--
Eyal Lebedinsky (eyal AT eyal DOT emu DOT id DOT au)
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -