Re: C90 fpeek

Liste des GroupesRevenir à cl c 
Sujet : Re: C90 fpeek
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
24 Jan 25 * C90 fpeek18Paul Edwards
24 Jan 25 +* Re: C90 fpeek16Keith Thompson
24 Jan 25 i+* Re: C90 fpeek3Paul Edwards
24 Jan 25 ii`* Re: C90 fpeek2Kaz Kylheku
24 Jan 25 ii `- Re: C90 fpeek1Paul Edwards
24 Jan 25 i+* Re: C90 fpeek3James Kuyper
24 Jan 25 ii`* Re: C90 fpeek2Michael S
26 Jan 25 ii `- Re: C90 fpeek1Lawrence D'Oliveiro
24 Jan 25 i`* Re: C90 fpeek9Kaz Kylheku
24 Jan 25 i +* Re: C90 fpeek4Chris M. Thomasson
25 Jan 25 i i+* Re: C90 fpeek2Kaz Kylheku
25 Jan 25 i ii`- Re: C90 fpeek1Chris M. Thomasson
26 Jan 25 i i`- Re: C90 fpeek1Lawrence D'Oliveiro
25 Jan 25 i +* Re: C90 fpeek3Paul Edwards
26 Jan 25 i i`* Re: C90 fpeek2Lawrence D'Oliveiro
27 Jan 25 i i `- Re: C90 fpeek1Paul Edwards
25 Jan 25 i `- Re: C90 fpeek1Kaz Kylheku
24 Jan 25 `- Re: C90 fpeek1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal