On Fri, Jan 11, 2019 at 6:59 PM Dave Horsfall <dave@horsfall.org> wrote:
On Fri, 11 Jan 2019, Noel Chiappa wrote:

[ ... ]

>         ioctl (0, FIONREAD, &nch);
>                        if (nch == 0) {
>                                tk_yield ();
>                                continue;
>                        }
>                }
>                if ((c = getchar()) == EOF) {
>
> so that ioctl() must look to see if there is any data waiting in the
> terminal input buffer (I'm too lazy to go see what FIONREAD does, right
> at the moment).

As I dimly recall (because I'm too sick/lazy to look it up), it returns
the number of characters in the input queue (at that time) so that you
won't block (and time out, if you wrote it thus).

It was quite useful, if you didn't like the horrible semantics of
select(), or, for that matter, SysV poll() (?) which was only slightly
better.

Of course, FIONREAD wasn't always reliable, because by the time you got to
using it the keyboard (l)user could have deleted some characters etc, and
you *could* be left there hanging on a timeout (with signals, which for
some reason I hate with a passion, as I've posted here before, as they
are just too brutal).

This is why RAW mode was born, but then you're duplicating the kernel cooking code in your ap :(
 
No doubt someone here will tell me that Plan9 did it right :-)  I really
must run it up some time, before I finally kark it (I'm in my late 60s).

No doubt...

Warner