Sujet : Re: C90 fpeek
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 25. Jan 2025, 01:50:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250124164433.252@kylheku.com>
References : 1 2 3 4 5
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-01-24, Scott Lurndal <
scott@slp53.sl.home> wrote:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
It absolutely does; have you never done a poll() or select() on a tty
file descriptor?
>
Hundreds of times over the last 35 years. Never on a buffered stdio
stream for which poll is basically useless.
It totally works, if done right.
And always with O_NONBLOCK set
on the file descriptor (from open, not fopen+fileno()), usually with
the underlying tty or pty set to so-called 'raw' mode.
You can fdopen that that, fread or getchar until EOF + errno ==
EWOULDBLOCK, then poll the fileno. Clear the error state with
clearerr and off you go: you can read from the stream to refill
its buffer and get bytes.
It can be very useful!
In any case, if you ever find yourself building a little buffering layer
over a file descriptor, it's something to think about: could the
requirements just be satisfied with old stdio?
Just because the requirements for situations like timed out reads, or
multiplexing multiple buffered streams with one thread --- that does not
pull stdio off the table!
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca