[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    ctermid(3S) manual page Table of Contents

Name

ctermid, ctermid_r - generate path name for controlling terminal

Synopsis

#include <stdio.h>

char *ctermid(char *s);

char *ctermid_r(char *s);

MT-Level

See the NOTES section of this page.

Description

ctermid() generates the path name of the controlling terminal for the current process, and stores it in a string.

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 header <stdio.h>.

ctermid_r() has the same functionality as ctermid() except that if s is a NULL pointer, the function returns NULL.

See Also

ttyname(3C)

Notes

The ctermid_r() interface is as proposed in the POSIX.4a Draft #6 document, and is subject to change to be compliant to the standard when it is accepted.

When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.

The difference between ctermid() and ttyname(3C) is that ttyname() must be handed a file descriptor and returns the actual name of the terminal associated with that file descriptor, while ctermid() returns a string (/dev/tty) that will refer to the terminal if used as a file name. Thus ttyname() is useful only if the process already has at least one file open to a terminal.

ctermid() is unsafe in multithreaded applications. ctermid_r() is MT-Safe, and should be used instead.


Table of Contents