On Sun, Mar 29, 2026 at 12:07:29PM +0200, Stian Skjelstad wrote:
> https://man7.org/linux/man-pages/man2/read.2.html
> 
> "On success, the number of bytes read is returned (zero indicates end of
> file)"
> 
> Hitting EOF is not an error, hence -1 would be incorrect.

curses returns -1 (ERR) on error conditions.
While there may be intervening calls after read which could produce a
different errno, in my quick tests I got EBADF after the curses call.

Klaas hasn't responded with any indication that they've checked errno.
 
> > EBADF  fd is not a valid file descriptor or is not open for reading.
> 
> This errorno would indicates that you tried to read from an invalid FD
> (random number, or after close() has been called from your process), or FD
> is not open for reading - only writing, ioctl or othet special purpose
> device.

sure - but curses doesn't reopen stdin, and if it returns ERR (-1),
checking errno is a first step toward diagnosing the problem as
seen by curses.
 
> (Not trying to flame war here, but this is expected behavior, atleast on
> Linux systems).
> 
> 
> Stian Skjelstad
> 
> 
> 
> 
> 
> On Sun, Mar 29, 2026, 11:59 Thomas Dickey <[email protected]>
> wrote:
> 
> > On Sun, Mar 29, 2026 at 11:40:56AM +0200, Stian Skjelstad wrote:
> > > > Actually what you're telling us is that there's a defect in (presumably
> > > Linux)
> > > > which should be documented in read(2).  Once you've gotten it
> > documented
> > > in
> > > >the proper place (Linux manpages), then others can use the
> > documentation.
> > >
> > > It is normal for read() to return 0, without an error when EOF is
> > reached.
> > > This is how you detect EOF/closed on sockets and files. Should TTY behave
> > > differently?
> >
> > man read(2)
> >
> >        EBADF  fd is not a valid file descriptor or is not open for reading.
> >
> > Klaas is describing a condition which isn't in the manpage - ymmv.
> >
> > --
> > Thomas E. Dickey <[email protected]>
> > https://invisible-island.net
> >

-- 
Thomas E. Dickey <[email protected]>
https://invisible-island.net

Attachment: signature.asc
Description: PGP signature

Reply via email to