Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ttyname(3) [php man page]

TTYNAME(3)						     Linux Programmer's Manual							TTYNAME(3)

ttyname, ttyname_r - return name of a terminal SYNOPSIS
#include <unistd.h> char *ttyname(int fd); int ttyname_r(int fd, char *buf, size_t buflen); DESCRIPTION
The function ttyname() returns a pointer to the null-terminated pathname of the terminal device that is open on the file descriptor fd, or NULL on error (for example, if fd is not connected to a terminal). The return value may point to static data, possibly overwritten by the next call. The function ttyname_r() stores this pathname in the buffer buf of length buflen. RETURN VALUE
The function ttyname() returns a pointer to a pathname on success. On error, NULL is returned, and errno is set appropriately. The func- tion ttyname_r() returns 0 on success, and an error number upon error. ERRORS
EBADF Bad file descriptor. ENOTTY File descriptor does not refer to a terminal device. ERANGE (ttyname_r()) buflen was too small to allow storing the pathname. ENODEV File descriptor refers to a slave pseudoterminal device but the corresponding pathname could not be found (see NOTES). ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +------------+---------------+------------------------+ |Interface | Attribute | Value | +------------+---------------+------------------------+ |ttyname() | Thread safety | MT-Unsafe race:ttyname | +------------+---------------+------------------------+ |ttyname_r() | Thread safety | MT-Safe | +------------+---------------+------------------------+ CONFORMING TO
POSIX.1-2001, POSIX.1-2008, 4.2BSD. NOTES
A process that keeps a file descriptor that refers to a pts(4) device open when switching to another mount namespace that uses a different /dev/ptmx instance may still accidentally find that a device path of the same name for that file descriptor exists. However, this device path refers to a different device and thus can't be used to access the device that the file descriptor refers to. Calling ttyname() or ttyname_r() on the file descriptor in the new mount namespace will cause these functions to return NULL and set errno to ENODEV. SEE ALSO
tty(1), fstat(2), ctermid(3), isatty(3), pts(4) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at Linux 2017-05-03 TTYNAME(3)

Check Out this Related Man Page

ttyname(3)						     Library Functions Manual							ttyname(3)

ttyname, isatty, ttyname_r - Get the name of a terminal LIBRARY
Standard C Library (, libc.a) SYNOPSIS
#include <unistd.h> char *ttyname( int file-descriptor); int isatty( int file-descriptor); int ttyname_r( int file-descriptor, char *buffer, int len); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: ttyname_r(): POSIX.1c isatty(), ttyname(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies an open file descriptor. Points to a buffer in which the terminal name is stored. Specifies the length of the buffer pointed to by the buffer parameter. DESCRIPTION
The ttyname() function gets the name of a terminal. It returns a pointer to a string containing the null-terminated pathname of the termi- nal device associated with the file-descriptor parameter. The isatty() function determines if the device associated with the file-descriptor parameter is a terminal. NOTES
The ttyname() function returns a pointer to thread-specific data. Subsequent calls to this function from the same thread overwrite this data. RETURN VALUES
Upon successful completion, the ttyname() function returns a pointer to a string identifying a terminal device. A NULL pointer is returned if the file-descriptor parameter does not describe a terminal device in the /dev directory. Upon successful completion, the isatty() function returns a value of 1 if the specified file-descriptor parameter is associated with a ter- minal. Otherwise, it returns a value of zero (0). [POSIX] Upon successful completion, the ttyname_r() function stores the terminal name as a null-terminated string in the buffer pointed to by the buffer parameter and returns a value of 0 (zero). Otherwise, it returns an error number. [Tru64 UNIX] The obsolete version of ttyname_r() functions the same way as the POSIX version, except it returns a -1 upon unsuccessful completion. ERRORS
If the isatty() function fails, errno may be set to the following value: The file associated with file-descriptor is not a terminal. If the ttyname_r() function fails, errno may be set to the following value: The buffer parameter is a null pointer or the len parameter was too short to store the string. RELATED INFORMATION
Functions: ttyslot(3) Standards: standards(5) delim off ttyname(3)
Man Page

Featured Tech Videos