This is the mail archive of the cygwin@sourceware.cygnus.com 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]

B19 problem


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@eyal.emu.id.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@eyal.emu.id.au)
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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