]> git.saurik.com Git - apple/libc.git/blame - stdlib/grantpt.3
Libc-1439.40.11.tar.gz
[apple/libc.git] / stdlib / grantpt.3
CommitLineData
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.\"
3d9156a7 32.\" $FreeBSD: src/lib/libc/stdlib/grantpt.3,v 1.3 2003/09/14 13:41:57 ru Exp $
9385eb3d 33.\"
224c7076 34.Dd February 2, 2005
9385eb3d
A
35.Os
36.Dt GRANTPT 3
37.Sh NAME
38.Nm grantpt ,
224c7076 39.Nm posix_openpt ,
9385eb3d 40.Nm ptsname ,
e07eda1a 41.Nm ptsname_r ,
224c7076 42.Nm unlockpt
9385eb3d 43.Nd pseudo-terminal access functions
9385eb3d
A
44.Sh SYNOPSIS
45.In stdlib.h
46.Ft int
224c7076
A
47.Fo grantpt
48.Fa "int fildes"
49.Fc
3d9156a7 50.Ft "char *"
224c7076
A
51.Fo ptsname
52.Fa "int fildes"
53.Fc
e07eda1a
A
54.Ft "int"
55.Fo ptsname_r
56.Fa "int fildes"
57.Fa "char *buffer"
58.Fa "size_t buflen"
59.Fc
9385eb3d 60.Ft int
224c7076
A
61.Fo unlockpt
62.Fa "int fildes"
63.Fc
64.In stdlib.h
9385eb3d
A
65.In fcntl.h
66.Ft int
224c7076
A
67.Fo posix_openpt
68.Fa "int oflag"
69.Fc
9385eb3d
A
70.Sh DESCRIPTION
71The
72.Fn grantpt ,
73.Fn ptsname ,
e07eda1a 74.Fn ptsname_r ,
9385eb3d
A
75.Fn unlockpt ,
76and
77.Fn posix_openpt
78functions allow access to pseudo-terminal devices.
e07eda1a 79The first four functions accept a file descriptor
9385eb3d
A
80that references the master half of a pseudo-terminal pair.
81This file descriptor is created with
82.Fn posix_openpt .
83.Pp
84The
85.Fn grantpt
86function is used to establish ownership and permissions
87of the slave device counterpart to the master device
88specified with
3d9156a7 89.Fa fildes .
9385eb3d 90The slave device's ownership is set to the real user ID
224c7076 91of the calling process; its permissions are set to
9385eb3d 92user readable-writable and group writable.
224c7076 93The group owner of the slave device is also set to the group
3d9156a7
A
94.Dq Li tty
95if it exists on the system; otherwise, it
9385eb3d
A
96is left untouched.
97.Pp
98The
99.Fn ptsname
e07eda1a
A
100and
101.Fn ptsname_r
102functions return the full pathname of the slave device
9385eb3d 103counterpart to the master device specified with
3d9156a7 104.Fa fildes .
9385eb3d
A
105This value can be used
106to subsequently open the appropriate slave after
107.Fn posix_openpt
108and
109.Fn grantpt
e07eda1a
A
110have been called. The
111.Fn ptsname
112function is not guaranteed to be reentrant or thread safe. The
113.Fn ptsname_r
114function takes a buffer and length as arguments to avoid this problem.
9385eb3d
A
115.Pp
116The
117.Fn unlockpt
224c7076
A
118function unlocks the slave pseudo-terminal device associated
119with the master device to which
120.Fa fildes
121refers.
9385eb3d
A
122.Pp
123The
124.Fn posix_openpt
125function opens the first available master pseudo-terminal
126device and returns a descriptor to it.
3d9156a7 127The
224c7076 128.Fa oflag
3d9156a7 129argument
9385eb3d 130specifies the flags used for opening the device:
3d9156a7 131.Bl -tag -width ".Dv O_NOCTTY"
9385eb3d
A
132.It Dv O_RDWR
133Open for reading and writing.
134.It Dv O_NOCTTY
135If set, do not allow the terminal to become
136the controlling terminal for the calling process.
137.El
138.Sh RETURN VALUES
3d9156a7 139.Rv -std grantpt unlockpt
9385eb3d
A
140.Pp
141The
142.Fn ptsname
143function returns a pointer to the name
3d9156a7
A
144of the slave device on success; otherwise a
145.Dv NULL
146pointer is returned and the global variable
9385eb3d
A
147.Va errno
148is set to indicate the error.
149.Pp
150The
e07eda1a
A
151.Fn ptsname_r
152function returns 0 if successful. On failure, it returns -1 and the global variable
153.Va errno
154is set to indicate the error.
155.Pp
156The
9385eb3d
A
157.Fn posix_openpt
158function returns a file descriptor to the first
159available master pseudo-terminal device on success;
3d9156a7 160otherwise \-1 is returned and the global variable
9385eb3d
A
161.Va errno
162is set to indicate the error.
163.Sh ERRORS
164The
165.Fn grantpt ,
166.Fn ptsname ,
e07eda1a 167.Fn ptsname_r ,
9385eb3d
A
168and
169.Fn unlockpt
170functions may fail and set
171.Va errno
172to:
173.Bl -tag -width Er
3d9156a7
A
174.It Bq Er EINVAL
175.Fa fildes
9385eb3d
A
176is not a master pseudo-terminal device.
177.El
178.Pp
179In addition, the
e07eda1a
A
180.Fn ptsname_r
181function may set
182.Va errno
183to:
184.Bl -tag -width Er
185.It Bq Er EINVAL
186The
187.Va buffer
188argument is NULL.
189.El
190.Bl -tag -width Er
191.It Bq Er ERANGE
192The
193.Va bufsize
194argument is smaller than the length of the string to be returned.
195.El
196.Pp
197In addition, the
9385eb3d
A
198.Fn grantpt
199function may set
200.Va errno
201to:
202.Bl -tag -width Er
3d9156a7 203.It Bq Er EACCES
9385eb3d
A
204The slave pseudo-terminal device could not be accessed.
205.El
206.Pp
207The
208.Fn posix_openpt
209function may fail and set
210.Va errno
211to:
212.Bl -tag -width Er
3d9156a7 213.It Bq Er EINVAL
224c7076 214.Fa oflag
3d9156a7
A
215consists of an invalid mode bit.
216.It Bq Er EAGAIN
9385eb3d
A
217The system has no available pseudo-terminal devices.
218.El
219.Pp
220The
221.Fn grantpt ,
222.Fn ptsname ,
e07eda1a 223.Fn ptsname_r ,
9385eb3d
A
224and
225.Fn unlockpt
226functions may also fail and set
227.Va errno
3d9156a7
A
228for any of the errors specified for the
229.Xr fstat 2
230system call.
9385eb3d
A
231.Pp
232The
233.Fn posix_openpt
234function may also fail and set
235.Va errno
3d9156a7
A
236for any of the errors specified for the
237.Xr open 2
238system call.
224c7076
A
239.Sh LEGACY SYNOPSIS
240.Fd #include <stdlib.h>
241.Fd #include <fcntl.h>
242.Pp
243.Ft int
244.br
245.Fo grantpt
246.Fa "int fildes"
247.Fc ;
248.Pp
249.Ft "char *"
250.br
251.Fo ptsname
252.Fa "int fildes"
253.Fc ;
254.Pp
255.Ft int
256.br
257.Fo unlockpt
258.Fa "int fildes"
259.Fc ;
260.Pp
261.Fd #include <fcntl.h>
262.Pp
263.Ft int
264.br
265.Fo posix_openpt
266.Fa "int oflag"
267.Fc ;
9385eb3d
A
268.Sh SEE ALSO
269.Xr open 2 ,
270.Xr pty 4 ,
224c7076
A
271.Xr tty 4 ,
272.Xr compat 5
9385eb3d
A
273.Sh STANDARDS
274The
275.Fn grantpt ,
276.Fn ptsname ,
277.Fn unlockpt ,
278and
279.Fn posix_openpt
280functions conform to
281.St -p1003.1-2001 .