ttyname_r() — Find path name of a terminal

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 2
Single UNIX Specification, Version 3

both OS/390 V2R8

Format

#define _XOPEN_SOURCE 500
#include <unistd.h>

int ttyname_r(int fildes, char *name, size_t namesize);

General description

The ttyname_r() function stores the NULL-terminated path name of the terminal associated with the file descriptor, fildes, in the character array referenced by name. The array is namesize characters long and should have space for the name and the terminating NULL character. The maximum length of the terminal name is TTY_NAME_MAX.

Returned value

If successful, ttyname_r() returns 0.

If unsuccessful, ttyname_r() sets errno to one of the following values:
EBADF
The fildes argument is not a valid file descriptor.
ENOTTY
The fildes argument does not refer to a tty.
ERANGE
The value of namesize is smaller than the length of the string to be returned including the terminating NULL character.

Related information