.TH ctermid() "" "" "General Function (libc)"
.PC "Name the terminal device that controls the current process"
\fB#include <stdio.h>\fR
\fBchar *ctermid (\fIpath_name\^\fB)\fR
\fBchar *\fIpath_name\fB;\fR
.PP
The general function
.B ctermid()
returns the full path name of the terminal device that controls the current
process.
It does for the controlling terminal what the function
.B ttyname()
does for a general file descriptor.
.PP
.I path_name
points to a block of memory into which
.B ctermid()
can write the name of the contolling terminal.
.II L_ctermid
It must point to at least
.B L_ctermid
bytes of available memory.
If
.I path_name
is NULL,
.B ctermid()
writes the name into a statically allocated buffer that may be overwritten
by subsequent calls to
.BR ctermid() .
.PP
If all goes well,
.B ctermid()
returns the address where it wrote the name of the controlling terminal.
If an error occurs \(em for example, it could not discover the name of the
controlling terminal \(em it returns an empty string.
.SH "See Also"
.Xr "libc" libc
.br
\*(PX 1003.1, \(sc4.7.1
.SH Notes
In almost every instance,
.B ctermid()
returns the string ``/dev/tty''.
Under \*(CO, the name of the controlling terminal for the current
process is
.BR /dev/tty .
Because some operating systems do not follow this
common practice, \*(PX provides
.B ctermid()
as a portable means of getting the controlling terminal's name.
