ISATTY(3C) Standard C Library Functions ISATTY(3C)

isattytest for a terminal device

Standard C Library (libc, -lc)

#include <unistd.h>

int
isatty(int filedes);

The () function tests whether fildes, an open file descriptor, is associated with a terminal device.

The isatty() function returns if fildes is associated with a terminal; otherwise it returns and errno is set to indicate the error.

The isatty() function may fail if:

The fildes argument is not a valid open file descriptor.
The fildes argument is not associated with a terminal.

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 () 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.

ttyname(3C), attributes(7), standards(7)

December 1, 2022 OmniOS