TTYNAME(3) Library Functions Manual TTYNAME(3)

ttyname ttyname_rfind pathname of a terminal

#include <unistd.h>

char *ttyname(int fildes);
int ttyname_r(int fildes, char *name, size_t namesize);

The ttyname() function returns a pointer to a string containing a null-terminated pathname of the terminal associated with file descriptor fildes . The return value may point to static data whose content is overwritten by each call.

The interface need not be reentrant.

The ttyname_r() function stores the null-terminated pathname of the terminal associated with the file descriptor in the character array referenced by . The array is characters long and should have space for the name and the terminating null character. The maximum length of the terminal name is {TTY_NAME_MAX}.

Upon successful completion, ttyname() returns a pointer to a string. Otherwise, a null pointer is returned and errno is set to indicate the error.

If successful, the ttyname_r() function returns zero. Otherwise, an error number is returned to indicate the error.

The ttyname() function may fail if:

The fildes argument is not a valid file descriptor.
The fildes argument does not refer to a terminal device.

The ttyname_r() function may fail if:

The fildes argument is not a valid file descriptor.
The fildes argument does not refer to a tty.
The value of namesize is smaller than the length of the string to be returned including the terminating null character.

None.

None.

None.

<unistd.h> .

ttyname() derived from Issue 1 of the SVID.

ttyname_r() derived from the POSIX Threads Extension (1003.1c-1995).

February 1997 posix.fail