Article View: pe.cust.wanted
Article #12inputpending works here
From: Tim Pointing
Date: Thu, 28 Mar 1985 13:17
Date: Thu, 28 Mar 1985 13:17
62 lines
2243 bytes
2243 bytes
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.
Technical Details
Message-ID:
<9@per.UUCP>Path:
arc1-ca.pugleaf.net!lsuc!nrcaero!pesnta!per!timShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Posting-Version: version B 2.10.2 9/18/84; site per.UUCP Path: arc1-ca.pugleaf.net!lsuc!nrcaero!pesnta!per!tim From: tim@per.UUCP (Tim Pointing) Newsgroups: pe.cust.wanted Subject: inputpending works here Message-ID: <9@per.UUCP> Date: 28 Mar 85 13:17:04 GMT Date-Received: 29 Mar 85 06:12:51 GMT Reply-To: tim@per.UUCP (Tim Pointing) Organization: D.C.I.E.M., Toronto, Canada Lines: 62