Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site cci-bdc.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!cybvax0!cci-bdc!jlup From: jlup@cci-bdc.UUCP (John Lupien ) Newsgroups: net.lang.c Subject: Re: C Input Question? Message-ID: <155@cci-bdc.UUCP> Date: Wed, 27-Feb-85 14:35:36 EST Article-I.D.: cci-bdc.155 Posted: Wed Feb 27 14:35:36 1985 Date-Received: Fri, 1-Mar-85 07:08:11 EST References: <1556@ritcv.UUCP> Distribution: net Organization: Computer Consoles, Inc., Cambridge, MA Lines: 65 > I am working an a very simple game using graphics text with a > GiGi terminal. I am having a big problem with the input. When > I get to a read, or any input statment, in C, everything stops > and waits for the input. > [text cut for brevity. Scott wants non-blocking I/O, that is "read if data, but don't wait for data.] > > Is there an easy way to do this in C. > I am doing this on a VAX running 4.2 if that makes a difference. > > scott hossler > rochester!ritcv!sah9577 Scott, your big problem lies in the use of a V7 manual. Read the 4.2 manual on tty(4) and fcntl(2) for the right way read without blocking. In brief; stty cbreak /* use ioctl, stty(2), whatever */ #include #include #include res = fcntl (stdin, F_SETFL, FNDELAY); if (res == -1) { printf("Can't set up terminal. Goodbye\n"); exit(1); } if (read (stdin, buf, bytes) == -1) { if (errno != EWOULDBLOCK) { printf ("Screwy I/O error: errno = %d. Bombing...\n", errno); exit(1); } noread = TRUE; } else { noread = FALSE; } if (noread) { /* do processing for *no input* condition */ } else { /* process input in buf. */ } Although the above is not in any sense a legal program, this is the kind of thing you need to do on 4.2 to get the functionality you describe. I hope I understood your needs, but this should be of general interest to BSD users anyway. -John Lupien CCI Boston Development Center 222 Third St. Cambridge,MA 02142