Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <unistd.h>
char *ctermid(char *string);
string points to a memory location where the ctermid() function stores the name of the current controlling terminal. The memory location must be able to hold at least L_ctermid characters, where L_ctermid is a symbol defined in the stdio.h header file.
ctermid() returns a string that can be used as a path name to refer to the controlling terminal for the current process. If string is not NULL, ctermid() stores the path name in the specified location and returns the value of string. Otherwise, ctermid() uses a location of its own and returns a pointer to that location.
The path name returned can be used to access the controlling terminal, if the process has a controlling terminal.
ctermid() is always successful; it returns a string that can be used as a path name to refer to the controlling terminal for the current process.
There are no documented errno values.
⁄* CELEBC32
This example refers to the controlling terminal for
the current process.
*⁄
#define _POSIX_SOURCE
#include <unistd.h>
#include <stdio.h>
main() {
char termid[1025];
if (ctermid(termid) == NULL)
perror("ctermid() error");
else
printf("The control terminal is %s\n", termid);
}
The control terminal is /dev/tty