ttyname()

NAME

ttyname(), isatty(), ttyslot() - get pathname of associated terminal (tty) from file descriptor

SYNOPSIS

#include <unistd.h>

char * ttyname (int fd) int isatty (int fd) int ttyslot(void)

DESCRIPTION

These functions operate on the system file descriptors for terminal type devices. These descriptors are not related to the standard I/O FILE typedef.

The isatty(2) function determines if the file descriptor fd refers to a valid terminal type device (serial devices, console windows and pseudo ttys).

The ttyname(2) function gets the related device name of a file descriptor for which isatty(2) is true. The name has the form /dev/ttyident, where the ident string specifies the type of the device and identifies it.

The ttyslot(3) function returns the index for the curent user's place in /var/adm/utmpx file, the user accounting database. The first entry is 0; the record represents the user's line. (A user's line in the database is an entry where utline matches the terminal device for one of the standard streams.)

RETURN VALUES

The ttyname(2) function returns the null-terminated name if the tty device is found and isatty(2) is true; otherwise it returns NULL and sets errno.

the ttyslot(3) function returns the index number for the entry; on failure, it returns -1 if there was an error, or if none of standard input, output or error for the process is associated with a terminal device.

The isatty(2) call returns zero if fd is not a valid terminal device and non-zero if it is.

ERROR

The ttyname(2) function can fail for the following reasons:

[EBADF]
The fd argument is not a valid descriptor.
[EIO]
Although the fd argument refers to a valid descriptor, the terminal device is no longer responsive.
[ENOTTY]
The fd argument does not refer to a terminal device.

FILES

/dev/*
The virtual device directory.

SEE ALSO

ctermid(3)