| Deutsch English Français Italiano |
|
<20250124164433.252@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: C90 fpeek Date: Sat, 25 Jan 2025 00:50:14 -0000 (UTC) Organization: A noiseless patient Spider Lines: 33 Message-ID: <20250124164433.252@kylheku.com> References: <vmv082$1u6pm$1@dont-email.me> <87plkc6bgm.fsf@nosuchdomain.example.com> <a7NkP.76379$ZEZf.241@fx40.iad> <20250124114602.417@kylheku.com> <fbUkP.928259$2xE6.372374@fx18.iad> Injection-Date: Sat, 25 Jan 2025 01:50:14 +0100 (CET) Injection-Info: dont-email.me; posting-host="25b6f8f1bdf7188549c4f808ba40c56c"; logging-data="2613194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VsrtgXv1+p/V3sAja/SPMPFxQjiT4/zA=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:CnRZayrTXAlSNcwfiYKfcsJ8lbE= Bytes: 2263 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