Relay-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Posting-Version: version B 2.10.1 6/24/83; site itm.UUCP Path: lsuc!nrcaero!pesnta!itm!danny From: danny@itm.UUCP (Danny) Newsgroups: pe.cust.wanted Subject: inputpending() routine - working program (LONG) Message-ID: <241@itm.UUCP> Date: 28 Mar 85 16:25:46 GMT Date-Received: 29 Mar 85 06:13:58 GMT References: <549@lsuc.UUCP> Reply-To: danny@itm.UUCP (Danny) Organization: In Touch - Atlanta, GA Lines: 108 Summary: It *is* possible under edition7-2.4 In article <549@lsuc.UUCP> dave@lsuc.UUCP (David Sherman) writes: >I asked in net.lang.c for a mechanism for FIONREAD (non-blocking >read) for v7, and the following was posted in reply... Dave, the following is a program that works on our system, a P-E 3210, running edition7 (version 2.4) (right now). There isn't much more to making it into a function that will return the number of chars waiting, the hardest thing is determining the index into the "vdu" array. You can do that by doing an fstat(2) on fd 0, 1, 2 (whichever is the terminal), getting the minor device number from fstat.st_rdev (minor is a macro in ) as the index into vdu. Like: fstat (1, &sbuf); i = minor (sbuf.st_rdev); if (i >= 0 && i < MAXTTY) return vdu[i].t_rawq.c_cc; else return 0; Boy, that was a screenful! Let's see if I can do it again; with the program this time: X# include X# include X# include X X# define NAME "cic" /* char input count */ X# define UNIX "/edition7" X# define MAXTTY 24 X# define MEM "/dev/mem" X# define READ 0 X# define BEG 0 X Xstruct nlist nl[] = { X "vdu", 0, 0, X "", 0, 0, X}; X Xstruct tty vdu[MAXTTY]; /* should be gotten from /usr/sys/conf/para.c */ X Xmain () X{ X int i, fd; X X nlist (UNIX, nl); X if (nl[0].n_type == 0 && nl[0].n_value == 0) { X printf ("%s: nlist failed.\n", NAME); X exit (-1); X } X fd = openf (MEM, READ, NAME); X for (;;) { X lseek (fd, (long) nl[0].n_value, BEG); X readf (fd, (char *) &vdu, sizeof (vdu), NAME, UNIX); X for (i = 0; i < 6; i++) X printf ("tty[%d] raw cnt is %d\n", i, vdu[i].t_rawq.c_cc); X sleep (4); X } X} X X# include X X/* openf --- open a file. Die if error. */ X Xopenf (fname, mode, cname) Xregister char *fname, *cname; Xregister int mode; X{ X register int fd; X extern int errno; X extern char *sys_errlist[]; X X if ((fd = open (fname, mode)) < 0) { X fprintf (stderr, "%s: can't open %s (%s)\n", cname, fname, X sys_errlist[errno]); X exit (-1); X } X return (fd); X} X X/* readf --- read n chars from file fd to buf. Die if error. */ X Xreadf (fd, buf, nc, cname, fname) Xregister int fd, nc; Xregister char *fname, *buf, *cname; X{ X register int nread; X extern int errno; X extern char *sys_errlist[]; X X nread = read (fd, buf, nc); X if (nread != nc) { X fprintf (stderr, "%s: read %d bytes from %s, wanted %d (%s)\n", X cname, nread, fname, nc, sys_errlist[errno]); X exit (-1); X } X} Well, I'd better shut up now. I didn't realize how long-winded a simple program can be... Hope this helps. Danny -- Daniel S. Cox ({gatech|akgua}!itm!danny)