Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: xtrace output sets ERRNO to 9 (EBADF)



2022-12-11 10:52:44 -0800, Bart Schaefer:
[...]
> In any case,
> fileno() doesn't set errno (it's just a data structure deref, would
> only fail by crashing)

Not that it matters much here, but POSIX does say that fileno()
shall  return -1 EBADF if "The stream is not associated with a
file." and may if "The file descriptor underlying stream is not
a valid file descriptor."

https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fileno.html

musl libc has:

int fileno(FILE *f)
{
        FLOCK(f);
        int fd = f->fd;
        FUNLOCK(f);
        if (fd < 0) {
                errno = EBADF;
                return -1;
        }
        return fd;
}

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author