#include <stdlib.h>char *ttyname(int fildes);
int ttyname_r(int fildes, char *buffer, size_t buflen);
int isatty(int fildes);
ttyname_r stores the null-terminated pathname of the terminal device associated with the file descriptor fildes in the string pointed to by buffer (up to buflen bytes).
isatty returns 1 if fildes is associated with a terminal device, 0 otherwise.
ttyname_r returns buffer on success.
ttyname_r returns NULL and ERANGE if buflen is smaller than the length of the string to be returned.
Use ttyname_r for multithreaded applications.
The older ttyname_r interface:
char *ttyname_r(int fildes, char *buffer, size_t buflen);is available if _SIMPLE_R is defined.