TTYNAME(3) BSD Programmer's Manual TTYNAME(3)NAME
ttyname, ttyname_r, isatty, ttyslot - get name of associated terminal
(tty) from file descriptor
SYNOPSIS
#include <unistd.h>
char *
ttyname(int fd);
int
ttyname_r(int fd, char *buf, size_t size);
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 type-
def, but refer to the special device files found in /dev and named
/dev/ttyxx and for which an entry exists in the initialization file
/etc/ttys. (See ttys(5).)
The isatty() function determines if the file descriptor fd refers to a
valid terminal type device.
The ttyname() function gets the related device name of a file descriptor
for which isatty() is true.
The ttyname_r() function is a reentrant version of the traditional
ttyname() function that fills in a supplied buffer buf of the given size,
which should be at least TTY_NAME_MAX characters long.
The ttyslot() function fetches the current process' control terminal num-
ber from the ttys(5) file entry.
RETURN VALUES
The ttyname() function returns the null terminated name if the device is
found and isatty() is true; otherwise a NULL pointer is returned.
The ttyname_r() function returns 0 on success, or the reason for failure
(see ERRORS). (In no case is the global variable errno changed.)
The ttyslot() function returns the unit number of the device file if
found; otherwise the value zero is returned.
ERRORS
[EBADF] The fd argument to ttyname() or ttyname_r() is invalid.
[ENOTTY] The fd argument to ttyname() or ttyname_r() does not refer to a
tty.
[ENOENT] While the fd argument to ttyname() or ttyname_r() appears to
refer to a tty, no name could be found for it.
[ERANGE] The buffer supplied to ttyname_r() is too small to hold the
name. (That is, the supplied size does not provide sufficient
room.)
FILES
/dev/*
/etc/ttys
SEE ALSOioctl(2), ttys(5)HISTORY
The isatty(), ttyname(), and ttyslot() functions appeared in Version 7
AT&T UNIX. The ttyname(), ttyname_r() and isatty() functions conform to
IEEE Std1003.1-1996 (``POSIX'').
BUGS
The ttyname() function leaves its result in an internal static object and
returns a pointer to that object. Subsequent calls to ttyname() will mod-
ify the same object.
The ttyname(), isatty(), and ttyslot() functions may not be safely called
concurrently from multiple threads, e.g., the interfaces described by
pthreads(3).
BSDI BSD/OS June 4, 1993 2