From: eyal AT eyal DOT emu DOT id DOT au (Eyal Lebedinsky) Subject: B19 problem 28 Feb 1998 08:31:56 -0800 Message-ID: <34F83754.426DCA0A.cygnus.gnu-win32@eyal.emu.id.au> References: <199802271045 DOT CAA10299 AT rtl DOT cygnus DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: gnu-win32 AT cygnus DOT com 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 */ #include #include /* STDIN_FILENO */ #include /* fcntl, F_SETFL, F_GETFL, O_NONBLOCK */ #include /* 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".