]>
Commit | Line | Data |
---|---|---|
9385eb3d A |
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 | .\" $FreeBSD: src/lib/libc/stdlib/grantpt.3,v 1.1 2003/01/02 20:44:41 jmallett Exp $ | |
33 | .\" | |
34 | .Dd December 23, 2002 | |
35 | .Os | |
36 | .Dt GRANTPT 3 | |
37 | .Sh NAME | |
38 | .Nm grantpt , | |
39 | .Nm ptsname , | |
40 | .Nm unlockpt , | |
41 | .Nm posix_openpt | |
42 | .Nd pseudo-terminal access functions | |
43 | .Sh LIBRARY | |
44 | .Lb libc | |
45 | .Sh SYNOPSIS | |
46 | .In stdlib.h | |
47 | .Ft int | |
48 | .Fn grantpt "int fildes" | |
49 | .Ft char * | |
50 | .Fn ptsname "int fildes" | |
51 | .Ft int | |
52 | .Fn unlockpt "int fildes" | |
53 | .In fcntl.h | |
54 | .Ft int | |
55 | .Fn posix_openpt "int mode" | |
56 | .Sh DESCRIPTION | |
57 | The | |
58 | .Fn grantpt , | |
59 | .Fn ptsname , | |
60 | .Fn unlockpt , | |
61 | and | |
62 | .Fn posix_openpt | |
63 | functions allow access to pseudo-terminal devices. | |
64 | The first three functions accept a file descriptor | |
65 | that references the master half of a pseudo-terminal pair. | |
66 | This file descriptor is created with | |
67 | .Fn posix_openpt . | |
68 | .Pp | |
69 | The | |
70 | .Fn grantpt | |
71 | function is used to establish ownership and permissions | |
72 | of the slave device counterpart to the master device | |
73 | specified with | |
74 | .Va fildes . | |
75 | The slave device's ownership is set to the real user ID | |
76 | of the calling process, and the permissions are set to | |
77 | user readable-writable and group writable. | |
78 | The group owner of the slave device is also set to the | |
79 | group "tty" if it exists on the system; otherwise, it | |
80 | is left untouched. | |
81 | .Pp | |
82 | The | |
83 | .Fn ptsname | |
84 | function returns the full pathname of the slave device | |
85 | counterpart to the master device specified with | |
86 | .Va fildes . | |
87 | This value can be used | |
88 | to subsequently open the appropriate slave after | |
89 | .Fn posix_openpt | |
90 | and | |
91 | .Fn grantpt | |
92 | have been called. | |
93 | .Pp | |
94 | The | |
95 | .Fn unlockpt | |
96 | function clears the lock held on the pseudo-terminal pair | |
97 | for the master device specified with | |
98 | .Va fildes . | |
99 | .Pp | |
100 | The | |
101 | .Fn posix_openpt | |
102 | function opens the first available master pseudo-terminal | |
103 | device and returns a descriptor to it. | |
104 | .Va mode | |
105 | specifies the flags used for opening the device: | |
106 | .Bl -tag -width O_NOCTTY | |
107 | .It Dv O_RDWR | |
108 | Open for reading and writing. | |
109 | .It Dv O_NOCTTY | |
110 | If set, do not allow the terminal to become | |
111 | the controlling terminal for the calling process. | |
112 | .El | |
113 | .Sh RETURN VALUES | |
114 | The | |
115 | .Fn grantpt | |
116 | and | |
117 | .Fn unlockpt | |
118 | functions return 0 on success; otherwise -1 is returned and | |
119 | .Va errno | |
120 | is set to indicate the error. | |
121 | .Pp | |
122 | The | |
123 | .Fn ptsname | |
124 | function returns a pointer to the name | |
125 | of the slave device on success; | |
126 | otherwise a NULL pointer is returned and | |
127 | .Va errno | |
128 | is set to indicate the error. | |
129 | .Pp | |
130 | The | |
131 | .Fn posix_openpt | |
132 | function returns a file descriptor to the first | |
133 | available master pseudo-terminal device on success; | |
134 | otherwise -1 is returned and | |
135 | .Va errno | |
136 | is set to indicate the error. | |
137 | .Sh ERRORS | |
138 | The | |
139 | .Fn grantpt , | |
140 | .Fn ptsname , | |
141 | and | |
142 | .Fn unlockpt | |
143 | functions may fail and set | |
144 | .Va errno | |
145 | to: | |
146 | .Bl -tag -width Er | |
147 | .It EINVAL | |
148 | .Va fildes | |
149 | is not a master pseudo-terminal device. | |
150 | .El | |
151 | .Pp | |
152 | In addition, the | |
153 | .Fn grantpt | |
154 | function may set | |
155 | .Va errno | |
156 | to: | |
157 | .Bl -tag -width Er | |
158 | .It EACCES | |
159 | The slave pseudo-terminal device could not be accessed. | |
160 | .El | |
161 | .Pp | |
162 | The | |
163 | .Fn posix_openpt | |
164 | function may fail and set | |
165 | .Va errno | |
166 | to: | |
167 | .Bl -tag -width Er | |
168 | .It EINVAL | |
169 | .Va mode | |
170 | consists an an invalid mode bit. | |
171 | .It EAGAIN | |
172 | The system has no available pseudo-terminal devices. | |
173 | .El | |
174 | .Pp | |
175 | The | |
176 | .Fn grantpt , | |
177 | .Fn ptsname , | |
178 | and | |
179 | .Fn unlockpt | |
180 | functions may also fail and set | |
181 | .Va errno | |
182 | for any of the errors specified for the routine | |
183 | .Xr fstat 2 . | |
184 | .Pp | |
185 | The | |
186 | .Fn posix_openpt | |
187 | function may also fail and set | |
188 | .Va errno | |
189 | for any of the errors specified for the routine | |
190 | .Xr open 2 . | |
191 | .Sh SEE ALSO | |
192 | .Xr open 2 , | |
193 | .Xr pty 4 , | |
194 | .Xr tty 4 | |
195 | .Sh STANDARDS | |
196 | The | |
197 | .Fn grantpt , | |
198 | .Fn ptsname , | |
199 | .Fn unlockpt , | |
200 | and | |
201 | .Fn posix_openpt | |
202 | functions conform to | |
203 | .St -p1003.1-2001 . | |
204 | .Sh HISTORY | |
205 | The | |
206 | .Fn grantpt , | |
207 | .Fn ptsname , | |
208 | .Fn unlockpt , | |
209 | and | |
210 | .Fn posix_openpt | |
211 | functions appeared in | |
212 | .Fx 5.0 . | |
213 | .Sh NOTES | |
214 | The purpose of the | |
215 | .Fn unlockpt | |
216 | function has no meaning in | |
217 | .Fx . | |
218 | .Pp | |
219 | The flag | |
220 | .Dv O_NOCTTY | |
221 | is included for compatibility; in | |
222 | .Fx , | |
223 | opening a terminal does not cause it to become | |
224 | a process's controlling terminal. |