Relay-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Posting-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Path: lsuc!dave From: dave@lsuc.UUCP (David Sherman) Newsgroups: pe.cust.wanted Subject: inputpending() routine - why won't this work? Message-ID: <549@lsuc.UUCP> Date: 27 Mar 85 12:59:59 GMT Date-Received: 27 Mar 85 12:59:59 GMT Organization: Law Society of Upper Canada, Toronto Lines: 70 I asked in net.lang.c for a mechanism for FIONREAD (non-blocking read) for v7, and the following was posted in reply: =From: sjoerd@tjalk.UUCP (Sjoerd Mullender) =Message-ID: <443@tjalk.UUCP> =Date: 21 Mar 85 13:00:48 GMT =Organization: VU Informatica, Amsterdam = =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; =} I figured out that the 0140000 should be changed to 0xff0000, or actually UBASE, which is defined in param.h. But when I tried compiling this with a test program main() { while(1) { if(inputpending()) printf("something\n"); else printf("nothing\n"); sleep(1); } } it always prints "nothing". I changed the unsigned c to int c, to correspond to the tty.h definition, and that didn't help either. What am I doing wrong. How can I get this to work? It would be very helpful for a number of programs, including rn. Dave Sherman -- {utzoo pesnta nrcaero utcs hcr}!lsuc!dave {allegra decvax ihnp4 linus}!utcsri!lsuc!dave