HP-UX Reference (11i v2 07/12) - 3 Library Functions A-M (vol 6)

c
ctermid(3S) ctermid(3S)
NAME
ctermid() - generate file name for terminal
SYNOPSIS
#include <stdio.h>
char *ctermid(char *s);
DESCRIPTION
ctermid() generates a string that, when used as a pathname, refers to the the controlling terminal for
the current process.
If s is a NULL pointer, the string is stored in an internal static area, the contents of which are overwritten
at the next call to ctermid() , and the address of which is returned. Otherwise, s is assumed to point to
a character array of at least
L_ctermid elements; the path name is placed in this array and the value of
s is returned. The constant
L_ctermid is defined in the <
stdio.h> header file.
If the process has no controlling terminal, the pathname for the controlling terminal cannot be determined,
or some other error occurs,
ctermid() returns an empty string.
For multi-thread applications, if s is a
NULL pointer, the operation is not performed and a NULL pointer is
returned.
NOTES
The difference between
ctermid() and ttyname() is that ttyname() must be handed a file descrip-
tor and returns the actual name of the terminal associated with that le descriptor, while
ctermid()
returns a string (/dev/tty) that refers to the terminal if used as a file name. (see ttyname(3C)). Thus
ttyname() is useful only if the process already has at least one file open to a terminal.
SEE ALSO
ttyname(3C), thread_safety(5).
STANDARDS CONFORMANCE
ctermid(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
HP-UX 11i Version 2: December 2007 Update 1 Hewlett-Packard Company 245