termio under SysV (kbdhit() and getch())

Leslie Mikesell les at chinet.chi.il.us
Fri Mar 3 05:26:40 AEST 1989


In article <1182 at naucse.UUCP> jdc at 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



More information about the Comp.unix.questions mailing list