Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site tjalk.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!mcvax!vu44!botter!tjalk!sjoerd From: sjoerd@tjalk.UUCP (Sjoerd Mullender) Newsgroups: net.lang.c Subject: Re: C Input Question? Message-ID: <443@tjalk.UUCP> Date: Thu, 21-Mar-85 08:00:48 EST Article-I.D.: tjalk.443 Posted: Thu Mar 21 08:00:48 1985 Date-Received: Sat, 23-Mar-85 01:39:07 EST References: <1556@ritcv.UUCP> <155@cci-bdc.UUCP> <247@faron.UUCP> <522@lsuc.UUCP> Reply-To: sjoerd@tjalk.UUCP (Sjoerd Mullender) Distribution: net Organization: VU Informatica, Amsterdam Lines: 51 Keywords: non-blocking read, PDP Summary: In article <522@lsuc.UUCP> dave@lsuc.UUCP (David Sherman) writes: >In article <247@faron.UUCP> meister@faron.UUCP (Philip W. Servita) writes: >||>[text cut for brevity. Scott wants non-blocking I/O, that is "read if >||>data, but don't wait for data.] >|| >|| ioctl(0,FIONREAD,&charwaiting); > >That's fine for BSD (which was the system the questioner wanted it for). >Anyone have an easy way of doing this for v7? I'm willing to do a >limited amount of kernel hacking. Here is a C routine that returns non-zero if there was any input pending. This is for a V7 PDP 11 system. The only requirement is that /dev/kmem is readable (which it should NOT be for security). #include #include #include 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); /* 0140000 is the beginning of the u area * u_ttyp is the pointer to the tty struct */ lseek(fd, (long) &((struct user *) 0140000)->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 2 byte 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; } -- Sjoerd Mullender ...!{decvax,philabs,seismo}!mcvax!vu44!sjoerd