Xref: utzoo comp.lang.c:28527 comp.unix.questions:22037 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!pdn!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Testing if keystrokes are waiting in the buffer (solution) Keywords: kbhit, UNIX, keypressed Message-ID: <26458520.3F0E@tct.uucp> Date: 7 May 90 14:24:31 GMT References: <1990Apr25.000456.25048@cunixf.cc.columbia.edu> <24107@mimsy.umd.edu> <684@n4hgf.uucp> Followup-To: comp.unix.questions Organization: ComDev/TCT, Sarasota, FL Lines: 18 Followups to comp.unix.questions. According to wht@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 ,