ttyname(3C) SDK R4.11 ttyname(3C)
NAME
ttyname, ttynamer, isatty - find name of a terminal
SYNOPSIS
#include <stdlib.h>
char *ttyname (int fildes);
char *ttynamer (int fildes, char *buffer, int buflen);
int isatty (int fildes);
DESCRIPTION
ttyname and ttynamer return a pointer to a string containing the
null-terminated pathname of the terminal device associated with file
descriptor fildes. Instead of returning static data, ttynamer
returns the string into the location pointed to by buffer. The return
value of ttynamer is the same as buffer. buffer has a length of
buflen characters. If ttynamer detects an error, a NULL is returned
and errno is set to indicate the error.
isatty returns 1 if fildes is associated with a terminal device, 0
otherwise.
Considerations for Threads Programming
+----------+-----------------------------+
| | async- |
|function | reentrant cancel cancel |
| | point safe |
+----------+-----------------------------+
|isatty | Y N N |
|ttyname | N - - |
|ttynamer | Y Y N |
+----------+-----------------------------+
FILES
/dev/* - Terminal device files.
/etc/ttysrch - List of directories under /dev containing tty device
files.
/etc/ttymap - Binary database mapping names of device files under
/dev with their major and minor device numbers.
DIAGNOSTICS
ttyname, isatty and ttynamer return a NULL pointer if fildes does
not describe a terminal device in the /dev directory.
Errors
If the following condition occurs, ttynamer returns NULL and set
errno to the corresponding value:
[ERANGE] The value of buflen is smaller than the length of the
string to be returned.
SEE ALSO
reentrant(3), ttyslot(3C), ttysrch(4M), ttymap(1M).
NOTES
The function ttynamer is available only in the shared library,
libc.so.
The return value for ttyname and isatty points to static data whose
content is overwritten by each call.
Licensed material--property of copyright holder(s)