ttyname(3C)
NAME
ttyname, ttyname_r, isatty − find name of a terminal
SYNOPSIS
#include <stdlib.h>
char ∗ttyname(int fildes);
char ∗ttyname_r(int fildes, char ∗buf, int len);
int isatty(int fildes);
MT-LEVEL
See the NOTES section of this page.
DESCRIPTION
ttyname() returns a pointer to a string containing the null-terminated path name of the terminal device associated with file descriptor fildes.
ttyname_r() has the equivalent functionality to ttyname() except that a buffer buf with length len must be supplied by the caller to store the result. buf must be at least _POSIX_PATH_MAX in size (defined in <limits.h>).
isatty() returns 1 if fildes is associated with a terminal device, 0 otherwise.
RETURN VALUES
ttyname() and ttyname_r() return a NULL pointer if fildes does not describe a terminal device in directory /dev.
ERRORS
ttyname_r() will fail if the following is true:
ERANGE The size of the buffer is smaller than the result to be returned.
FILES
/dev/∗
SEE ALSO
NOTES
The ttyname_r() interface is as proposed in the POSIX.4a Draft #6 document, and is subject to change to be compliant to the standard when it is accepted.
When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.
If the application is linked with −lintl, then messages printed from this function are in the native language specified by the LC_MESSAGES locale category; see setlocale(3C).
The return value points to static data whose content is overwritten by each call.
ttyname() is unsafe in multi-thread applications. ttyname_r() is MT-Safe, and should be used instead. isatty() is MT-Safe in multi-thread applications.
Sun Microsystems — Last change: 22 Jan 1993