The functions described in this chapter only work on files that
correspond to terminal devices. You can find out whether a file
descriptor is associated with a terminal by using the
Prototypes for the functions in this section are declared in the header file unistd.h.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This function returns
1 if filedes is a file descriptor
associated with an open terminal device, and 0 otherwise.
If a file descriptor is associated with a terminal, you can get its
associated file name using the
ttyname function. See also the
ctermid function, described in Identifying the Controlling Terminal.
Preliminary: | MT-Unsafe race:ttyname | AS-Unsafe heap lock | AC-Unsafe lock fd mem | See POSIX Safety Concepts.
If the file descriptor filedes is associated with a terminal
ttyname function returns a pointer to a
statically-allocated, null-terminated string containing the file name of
the terminal file. The value is a null pointer if the file descriptor
isn’t associated with a terminal, or the file name cannot be determined.
Preliminary: | MT-Safe | AS-Unsafe heap | AC-Unsafe mem fd | See POSIX Safety Concepts.
ttyname_r function is similar to the
except that it places its result into the user-specified buffer starting
at buf with length len.
The normal return value from
ttyname_r is 0. Otherwise an
error number is returned to indicate the error. The following
errno error conditions are defined for this function:
The filedes argument is not a valid file descriptor.
The filedes is not associated with a terminal.
The buffer length len is too small to store the string to be returned.
The filedes is associated with a terminal device that is a slave pseudo-terminal, but the file name associated with that device could not be determined. This is a GNU extension.