xref: /freebsd/lib/libc/gen/ctermid.3 (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd June 2, 2026
29.Dt CTERMID 3
30.Os
31.Sh NAME
32.Nm ctermid ,
33.Nm ctermid_r
34.Nd generate terminal pathname
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In stdio.h
39.Ft char *
40.Fn ctermid "char *buf"
41.Ft char *
42.Fn ctermid_r "char *buf"
43.Sh DESCRIPTION
44The
45.Fn ctermid
46function generates a string, that, when used as a pathname, refers to
47the current controlling terminal of the calling process.
48.Pp
49If
50.Fa buf
51is the
52.Dv NULL
53pointer, a pointer to a static area is returned.
54Otherwise, the pathname is copied into the memory referenced by
55.Fa buf .
56The argument
57.Fa buf
58is assumed to be at least
59.Dv L_ctermid
60(as defined in the include
61file
62.In stdio.h )
63bytes long.
64.Pp
65The
66.Fn ctermid_r
67function
68provides the same functionality as
69.Fn ctermid
70except that if
71.Fa buf
72is a
73.Dv NULL
74pointer,
75.Dv NULL
76is returned.
77.Pp
78If no suitable lookup of the controlling terminal name can be performed,
79this implementation returns
80.Ql /dev/tty .
81.Sh RETURN VALUES
82The
83.Fn ctermid
84function returns
85.Fa buf
86if it is
87.Pf non- Dv NULL ,
88otherwise it returns the address of a static buffer.
89The
90.Fn ctermid_r
91function always returns
92.Fa buf ,
93even if it is the NULL pointer.
94.Sh ERRORS
95The current implementation detects no error conditions.
96.Sh SEE ALSO
97.Xr ttyname 3
98.Sh STANDARDS
99The
100.Fn ctermid
101function conforms to
102.St -p1003.1-88 .
103.Sh BUGS
104By default the
105.Fn ctermid
106function
107writes all information to an internal static object.
108Subsequent calls to
109.Fn ctermid
110will modify the same object.
111