#include <lcio.h> char *ctermid(char *termid);The synopsis for the POSIX implementation is as follows:
#include <unistd.h> char *ctermid(char *termid);
This set of header files requires the definition of an appropriate feature test macro. See Feature Test Macros for more information.
ctermid
returns the filename of the user's terminal.
string
is the terminal filename.
The argument to ctermid
should be NULL
, or it should address a
character array (termid
) whose size is at least L_ctermid
.
The symbol L_ctermid
is defined in the header file
<lcio.h>
(or <stdio.h>
if an appropriate feature test macro
is defined).
If the argument is not NULL
, the filename (followed by '\0') is copied
into the area addressed by termid
. If the argument is NULL
, the
filename can only be accessed by using the value returned by ctermid
.
ctermid
is NULL
(the norm), the return value is in
static storage and may be overlaid by the next call to ctermid
.
ctermid
, an attempt to open the
filename returned by ctermid
may fail.
#include <lcio.h> main() { /* Open the terminal for writing. */ FILE *termfile; /* Assign name of interactive terminal to termfile. */ termfile = fopen(ctermid(NULL), "w"); if (!termfile) { printf("File could not be opened.n", stderr); exit(1); } /* Print message to interactive terminal. */ fprintf(termfile, "This is a test message.n"); fclose(termfile); }
ttyname