Checking an fd for pending data (sans select(3))

William Davidsen davidsen at sungod.crd.ge.com
Thu Aug 3 04:26:57 AEST 1989


  The name for the procedure which tells you if a key has been pressed
is usually kbhit(), and what you need is fkbhit() I guess. In SysV you
can set the read to timeout with an ioctl. The values to set are in the
control structure. Here's a code fragment (you want to modify it).

	ioctl(0, TCGETA, &otermio);	/* save old settings */
	ntermio.c_iflag = 0;		/* setup new settings */
	ntermio.c_oflag = 0;
	ntermio.c_cflag = otermio.c_cflag;
	ntermio.c_lflag = 0;
	ntermio.c_line = otermio.c_line;
	ntermio.c_cc[VMIN] = 1;
	ntermio.c_cc[VTIME] = 0;
	ioctl(0, TCSETAW, &ntermio);	/* and activate them */

Good luck.
	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.wizards mailing list