]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/stdlib/ptsname.3
Merge llvm-project main llvmorg-17-init-19304-gd0b54bb50e51
[FreeBSD/FreeBSD.git] / lib / libc / stdlib / ptsname.3
1 .\"
2 .\" Copyright (c) 2002 The FreeBSD Project, Inc.
3 .\" All rights reserved.
4 .\"
5 .\" This software includes code contributed to the FreeBSD Project
6 .\" by Ryan Younce of North Carolina State University.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the FreeBSD Project nor the names of its
17 .\"    contributors may be used to endorse or promote products derived from
18 .\"    this software without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS
21 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 .\" PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FREEBSD PROJECT
24 .\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26 .\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 .\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .\"
32 .Dd October 14, 2023
33 .Dt PTSNAME 3
34 .Os
35 .Sh NAME
36 .Nm grantpt ,
37 .Nm ptsname ,
38 .Nm ptsname_r ,
39 .Nm unlockpt
40 .Nd pseudo-terminal access functions
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In stdlib.h
45 .Ft int
46 .Fn grantpt "int fildes"
47 .Ft "char *"
48 .Fn ptsname "int fildes"
49 .Ft "int"
50 .Fn ptsname_r "int fildes" "char *buffer" "size_t buflen"
51 .Ft int
52 .Fn unlockpt "int fildes"
53 .Sh DESCRIPTION
54 The
55 .Fn grantpt ,
56 .Fn ptsname ,
57 and
58 .Fn unlockpt
59 functions allow access to pseudo-terminal devices.
60 These three functions accept a file descriptor that references the
61 master half of a pseudo-terminal pair.
62 This file descriptor is created with
63 .Xr posix_openpt 2 .
64 .Pp
65 The
66 .Fn grantpt
67 function is used to establish ownership and permissions
68 of the slave device counterpart to the master device
69 specified with
70 .Fa fildes .
71 The slave device's ownership is set to the real user ID
72 of the calling process, and the permissions are set to
73 user readable-writable and group writable.
74 The group owner of the slave device is also set to the
75 group
76 .Dq Li tty .
77 .Pp
78 The
79 .Fn ptsname
80 function returns the full pathname of the slave device
81 counterpart to the master device specified with
82 .Fa fildes .
83 This value can be used
84 to subsequently open the appropriate slave after
85 .Xr posix_openpt 2
86 and
87 .Fn grantpt
88 have been called.
89 .Pp
90 The
91 .Fn ptsname_r
92 function is the thread-safe version of
93 .Fn ptsname .
94 The caller must provide storage for the results of the full pathname of
95 the slave device in the
96 .Fa buffer
97 and
98 .Fa bufsize
99 arguments.
100 .Pp
101 The
102 .Fn unlockpt
103 function clears the lock held on the pseudo-terminal pair
104 for the master device specified with
105 .Fa fildes .
106 .Sh RETURN VALUES
107 .Rv -std grantpt unlockpt
108 .Pp
109 The
110 .Fn ptsname
111 function returns a pointer to the name
112 of the slave device on success; otherwise a
113 .Dv NULL
114 pointer is returned.
115 .Pp
116 The
117 .Fn ptsname_r
118 function returns the value 0 if successful;
119 otherwise a nonzero value is returned and the global variable
120 .Va errno
121 is set to indicate the error.
122 Note:
123 .Fn ptsname_r
124 was previously documented as returning -1 on error.
125 In the future it will be changed to return an error number, for POSIX
126 compatibility.
127 Therefore, callers should not check for -1.
128 .Sh ERRORS
129 The
130 .Fn grantpt ,
131 .Fn ptsname ,
132 .Fn ptsname_r
133 and
134 .Fn unlockpt
135 functions may fail and set
136 .Va errno
137 to:
138 .Bl -tag -width Er
139 .It Bq Er EBADF
140 .Fa fildes
141 is not a valid open file descriptor.
142 .It Bq Er EINVAL
143 .Fa fildes
144 is not a master pseudo-terminal device.
145 .El
146 .Pp
147 In addition, the
148 .Fn ptsname_r
149 function may set
150 .Va errno
151 to:
152 .Bl -tag -width Er
153 .It Bq Er ERANGE
154 The buffer was too small.
155 .El
156 .Pp
157 In addition, the
158 .Fn grantpt
159 function may set
160 .Va errno
161 to:
162 .Bl -tag -width Er
163 .It Bq Er EACCES
164 The slave pseudo-terminal device could not be accessed.
165 .El
166 .Sh SEE ALSO
167 .Xr posix_openpt 2 ,
168 .Xr pts 4 ,
169 .Xr tty 4
170 .Sh STANDARDS
171 The
172 .Fn ptsname
173 function conforms to
174 .St -p1003.1-2008 .
175 .Pp
176 This implementation of
177 .Fn grantpt
178 and
179 .Fn unlockpt
180 does not conform to
181 .St -p1003.1-2008 ,
182 because it depends on
183 .Xr posix_openpt 2
184 to create the pseudo-terminal device with proper permissions in place.
185 It only validates whether
186 .Fa fildes
187 is a valid pseudo-terminal master device.
188 Future revisions of the specification will likely allow this behaviour,
189 as stated by the Austin Group.
190 .Sh HISTORY
191 The
192 .Fn grantpt ,
193 .Fn ptsname
194 and
195 .Fn unlockpt
196 functions appeared in
197 .Fx 5.0 .