Xref: utzoo comp.sys.att:5715 comp.unix.questions:11984 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!rutgers!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.sys.att,comp.unix.questions Subject: Re: termio under SysV (kbdhit() and getch()) Message-ID: <7851@chinet.chi.il.us> Date: 2 Mar 89 19:26:40 GMT References: <1174@naucse.UUCP> <1182@naucse.UUCP> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Followup-To: comp.sys.att Distribution: usa Organization: Chinet - Public Access Unix Lines: 23 In article <1182@naucse.UUCP> jdc@naucse.UUCP (John Campbell) writes: >And the bad news is that I no longer have a valid plan for implementing >a peek into the typeahead buffer at all! Anyone know if this can be done >under SysV? (And, of course, how it is done?) What you have to do is read the characters into your own buffer and then you can peek all you like. The point you are missing is that VMIN is the minimum number of characters to be returned unless VTIME expires between characters. That is, if VMIN is greater than zero a read will block forever waiting for the first character, then return when VMIN characters have come in or VTIME tenths of seconds elapses between characters, whichever comes first. If VMIN is 0, then the read will return immediately if no characters are available. You can also use fcntl() to set O_NDELAY for this effect but you have to turn it back off before writing to the device. However, keep in mind that it is expensive to loop doing non-blocking reads. It might be better to fork off a process that could block waiting for input, or if you are really just watching for an indication to quit doing whetever else you are doing in the loop you can use one of the tty-generated signals and forget the read() entirely. Les Mikesell