ctermid() - generate terminal pathname
#include <stdio.h>
char * ctermid (char *buf)
The ctermid(3) function generates a string that, when used as a pathname, refers to the current controlling terminal of the calling process.
If buf is the NULL pointer, the function returns a pointer to a static area. Otherwise, the pathname is copied into the memory referenced by buf. The argument buf is assumed to be at least {L_ctermid} (as defined in the include file <stdio.h>) bytes long.
This implementation of the ctermid(3) function always returns /dev/tty.
ttyname(2)