Testing if keystrokes are waiting in the buffer (solution)

Chip Salzenberg chip at tct.uucp
Tue May 8 00:24:31 AEST 1990


Followups to comp.unix.questions.

According to wht at n4hgf.UUCP (Warren Tucker):
>XENIX V, SCO UNIX, UNIX Sys V Rel 4:
>      if(rdchk(0))  /* if ICANON is on, rdchk will report nothing until
>                     * newline or whatever is typed */
>      {
>         data is waiting ...
>      }

A nit: rdchk() returns -1 for error, zero if a read() will block, and
a positive integer if a read() will not block.  Check those errors!

Note that if you opened with O_NDELAY, or if you turned on the NDELAY
bit with fcntl(), then rdchk() will *always* return a positive
integer.  After all, with NDELAY on, read() never blocks.  Sigh.
-- 
Chip Salzenberg at ComDev/TCT   <chip%tct at ateng.com>, <uunet!ateng!tct!chip>



More information about the Comp.lang.c mailing list