Subject: B19 problem
From: [email-masked] (Eyal Lebedinsky)

28 Feb 1998 08:31:56 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked]

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 <[email-masked]>
*/

#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		([email-masked])
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".