Path: utzoo!attcan!uunet!husc6!rutgers!cmcl2!phri!marob!daveh From: daveh@marob.MASA.COM (Dave Hammond) Newsgroups: comp.unix.questions Subject: Re: Querying tty input with ioctl Keywords: ioctl I/O device driver Message-ID: <333@marob.MASA.COM> Date: 18 Jul 88 12:44:52 GMT References: <11527@steinmetz.ge.com> Reply-To: daveh@marob.UUCP (Dave Hammond) Distribution: na Organization: 18th Street Construction Co NY NY Lines: 28 In article ron@topaz.rutgers.edu (Ron Natalie) writes: >I believe what you are asking is how to detect when there >is TTY input to read. This can be done with the select >call. A simplistic example: >[...stuff deleted...] > select(1, &rflags, (int *) 0, (int *) 0, &tv); > if(rflags) { > /* There is something to read */ > read(ttyfd, &c, 1); > } Or in SysV land- #include int fcntl_flags = fcntl(0, F_GETFL, 0); /* get fcntl flags */ fcntl(0, F_SETFL, fcntl_flags | O_NDELAY); /* set "no delay" */ if (read(0, &ch, 1) > 0) /* there's a char queued */ do_something(); fcntl(0, F_SETFL, fcntl_flags); /* unset "no delay" */ Read in O_NDELAY mode will return -1 of the read would block (i.e. there are no chars waiting in the tty queue). This allows you to check for pending input without causing the program to "block" waiting for input. Dave Hammond UUCP: {uunet|rutgers|spl1|...}!hombre!marob!daveh -----------------------------------------------------