HELP: Low level terminal I/O
"Gary S. Moss", VLD/VMB
moss at BRL.MIL
Sat Jul 29 00:05:04 AEST 1989
[Misha Pavel <mis at psych.Stanford.Edu> writes]
< Is there any way to look at the system buffer and or return
< from read() when no input was generated?
Probably the better way to go, rather than mucking around with the terminal
settings, is to use fcntl() as follows:
Where fd is a file descriptor returned from creat(), open(), dup(),
fcntl(), or pipe().
#include <fcntl.h>
(void) fcntl( fd, F_SETFL, O_NDELAY );
/* to check the buffer... */
if( read( fd, bufptr, bytes ) == 0 )
; /* nothing to read */
To be portable to BSD systems, the following is more correct:
got = read( fd, bufptr, bytes);
#ifdef BSD
if( got == -1 && errno == EWOULDBLOCK )
got = 0; /* act like System V */
#endif
if( got == 0 )
; /* nothing to read */
Do a 'man fcntl' for more info.
-moss
More information about the Comp.sys.sgi
mailing list