ttyname -- Get Terminal Name


SYNOPSIS
#include <sys/types.h>
#include <unistd.h>
char *ttyname(int fn);
DESCRIPTION
ttyname
returns the name of the OpenEdition terminal associated
with the file descriptor fn
. The ttyname
function returns NULL
if
the file descriptor is not open, or if it does not refer to an OpenEdition
terminal.
RETURN VALUE
ttyname
returns the name of the terminal if it is successful
and a NULL pointer if it is not successful.
CAUTION
Subsequent calls to ttyname
may overwrite the terminal name
string.
EXAMPLE
This example determines, for each of the standard POSIX files,
whether the file is a terminal and, if so, prints its name:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
main() {
char *name;
int count = 0;
name = ttyname(STDIN_FILENO);
if (name) {
++count;
printf("The standard input is a terminal file named %sn",
name);
}
name = ttyname(STDOUT_FILENO);
if (name) {
++count;
printf("The standard output is a terminal file named %sn",
name);
}
name = ttyname(STDERR_FILENO);
if (name) {
++count;
printf("The standard error output is a terminal file named %sn",
name);
}
if (!count)
puts("None of the standard files is a terminal file.");
return 0;
}
RELATED FUNCTIONS
ctermid
SEE ALSO