[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: isatty() and errno
From: |
Bruno Haible |
Subject: |
Re: isatty() and errno |
Date: |
Tue, 8 Nov 2011 12:33:36 +0100 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Eric Blake wrote:
> that means it is likely that other GNU code will assume isatty()
> sets errno. Should we provide an isatty() module that guarantees that
> errno will be set when returning 0?
The fact that isatty() always sets errno in glibc is undocumented:
-- Function: int isatty (int FILEDES)
This function returns `1' if FILEDES is a file descriptor
associated with an open terminal device, and 0 otherwise.
And the POSIX wording is (emphasis is mine):
The isatty() function shall return 1 if fildes is associated
with a terminal; otherwise, it shall return 0 and *may* set
errno to indicate the error.
People should program against standards. So people should get used to
write
errno = 0;
if (!isatty (fd))
{
if (errno == 0)
errno = ENOTTY;
}
even if it looks complicated. That's the way the standard is.
Bruno
--
In memoriam The inmates of the Daugavpils Ghetto
<http://en.wikipedia.org/wiki/Daugavpils_Ghetto>