[pe.cust.wanted] inputpending works here

tim@per.UUCP (Tim Pointing) (03/28/85)

I tried the version of inputpending posted recently by Dave Sherman (dave@lsuc)
and, after making the 0140000 <=> UBASE correction and including <sys/tty.h>
(required for FIOCLEX), inputpending worked just fine. I have confidence that
this is not due to the modified tty driver that we are running here. Included
below is the exact source for the test that I ran...


> main()
> {
> 	while(1)
> 	{
> 		if(inputpending())
> 			printf("something\n");
> 		else
> 			printf("nothing\n");
> 		sleep(1);
> 	}
> }
> 
> #include <sys/param.h>
> #include <sys/dir.h>
> #include <sys/user.h>
> #include <sys/tty.h>
> 
> inputpending()
> {
> 	static int fd = -2;
> 	unsigned c;
> 
> 	if (fd == -2)	/* uninitialized */
> 		if ((fd = open("/dev/kmem", 0)) >= 0) {
> 			/* If the open fails, fd will be -1, so we won't
> 			 * try again.
> 			 * Close the file descriptor on exec.
> 			 */
> 			ioctl(fd, FIOCLEX, (struct sgttyb *) 0);
> 			/*
> 			 * u_ttyp is the pointer to the tty struct
> 			 */
> 			lseek(fd, (long) &((struct user *) UBASE)->u_ttyp, 0);
> 			read(fd, &c, sizeof c);
> 			/* seek to the beginning of the tty struct */
> 			lseek(fd, (long) c, 0);
> 		}
> 	if (fd < 0)
> 		return 0;
> 	/* the first int of the tty struct is a pointer to the clist */
> 	if (read(fd, &c, sizeof c) < sizeof c)
> 		return 0;
> 	lseek(fd, - (long) sizeof c, 1);
> 	/* there is input when the pointer to the clist is != 0 */
> 	return c != 0;
> }

Hope this works for you.

Dave - is this not exactly what you have?

For those lucky enough to have source, you can very easily add an ioctl call
similar to the Berkley FIONREAD, as we have done here, which functions for
tty's. If anybody wants that code, drop me a line - its only a couple of lines
of code.