[comp.unix.wizards] Checking an fd for pending data

kender@eleazar.dartmouth.edu (Too hot to handle) (08/02/89)

I'd like a function (in C for all you fortran holdouts) that would tell me
if there is data on the stream to read, this would be ideal:
	if (pending(fd) == 1) { /* there is data to read
		... read data ...
	} else {		/* no data...we can go on */
		...
	}

this is for SYS V and I'm sans a select...so keep that in mind.
thanx in advance.
-k
********************************************************************************
     Cathy Huse: HB 1326, Dartmouth College, Hanover, New Hampshire; 03755
                InterNet: kender@eleazar.dartmouth.edu
      "What does an actor want with a conscience anyway?" --Jiminy Cricket

davidsen@sungod.crd.ge.com (William Davidsen) (08/03/89)

  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@crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me