ISATTY(3C) | Standard C Library Functions | ISATTY(3C) |
isatty
— test for
a terminal device
Standard C Library (libc, -lc)
#include
<unistd.h>
int
isatty
(int filedes);
The
isatty
()
function tests whether fildes, an open file
descriptor, is associated with a terminal device.
The isatty
() function returns
1 if
fildes is associated with a terminal; otherwise it
returns 0 and
errno is set to indicate the error.
The isatty
() function may fail if:
The isatty
() function does not necessarily
indicate that a human being is available for interaction via
fildes. It is quite possible that non-terminal devices
are connected to the communications line.
There are a few portability concerns to be aware of.
POSIX does not strictly require that the
isatty
()
function actually set and update errno. The only
portable and reliable thing to do is to check the return value. Older
versions of this implementation did not set errno and
erroneously preserved errno when the
isatty
() function returned 0. In cases where true
portability is required, one should set errno to zero
before calling this function to potentially allow for and distinguish this
case.
December 1, 2022 | OmniOS |