From owner-freebsd-hackers Tue Jul 22 23:17:43 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id XAA27191 for hackers-outgoing; Tue, 22 Jul 1997 23:17:43 -0700 (PDT) Received: from scanner.worldgate.com (scanner.worldgate.com [198.161.84.3]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id XAA27186 for ; Tue, 22 Jul 1997 23:17:41 -0700 (PDT) Received: from znep.com (uucp@localhost) by scanner.worldgate.com (8.8.5/8.8.5) with UUCP id AAA23362; Wed, 23 Jul 1997 00:17:08 -0600 (MDT) Received: from localhost (marcs@localhost) by alive.znep.com (8.7.5/8.7.3) with SMTP id AAA24955; Wed, 23 Jul 1997 00:18:41 -0600 (MDT) Date: Wed, 23 Jul 1997 00:18:40 -0600 (MDT) From: Marc Slemko To: Paul Traina cc: hackers@FreeBSD.ORG Subject: Re: how to tell if getchar() will block -- select doesn't cut it In-Reply-To: <199707230509.WAA13342@precipice.shockwave.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk If you can't tell if getchar() will block, how about just making it so it won't block? Say something like: fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) Then just do a getchar() and make the appropriate checks to see if it actually got something or if it returned EAGAIN in errno. Not completely portable, and some systems return EWOULDBLOCK instead, but it may do what you want... On Tue, 22 Jul 1997, Paul Traina wrote: > I had some fun this week -- I'd added some asynchronous event code to a > little line editor so that I could deal with some events while waiting > from user input... > > The code looked something like: > >