]> git.saurik.com Git - apple/libc.git/blame - stdlib/grantpt.3
Libc-1044.40.1.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 ,
224c7076 41.Nm unlockpt
9385eb3d 42.Nd pseudo-terminal access functions
9385eb3d
A
43.Sh SYNOPSIS
44.In stdlib.h
45.Ft int
224c7076
A
46.Fo grantpt
47.Fa "int fildes"
48.Fc
3d9156a7 49.Ft "char *"
224c7076
A
50.Fo ptsname
51.Fa "int fildes"
52.Fc
9385eb3d 53.Ft int
224c7076
A
54.Fo unlockpt
55.Fa "int fildes"
56.Fc
57.In stdlib.h
9385eb3d
A
58.In fcntl.h
59.Ft int
224c7076
A
60.Fo posix_openpt
61.Fa "int oflag"
62.Fc
9385eb3d
A
63.Sh DESCRIPTION
64The
65.Fn grantpt ,
66.Fn ptsname ,
67.Fn unlockpt ,
68and
69.Fn posix_openpt
70functions allow access to pseudo-terminal devices.
71The first three functions accept a file descriptor
72that references the master half of a pseudo-terminal pair.
73This file descriptor is created with
74.Fn posix_openpt .
75.Pp
76The
77.Fn grantpt
78function is used to establish ownership and permissions
79of the slave device counterpart to the master device
80specified with
3d9156a7 81.Fa fildes .
9385eb3d 82The slave device's ownership is set to the real user ID
224c7076 83of the calling process; its permissions are set to
9385eb3d 84user readable-writable and group writable.
224c7076 85The group owner of the slave device is also set to the group
3d9156a7
A
86.Dq Li tty
87if it exists on the system; otherwise, it
9385eb3d
A
88is left untouched.
89.Pp
90The
91.Fn ptsname
92function returns the full pathname of the slave device
93counterpart to the master device specified with
3d9156a7 94.Fa fildes .
9385eb3d
A
95This value can be used
96to subsequently open the appropriate slave after
97.Fn posix_openpt
98and
99.Fn grantpt
100have been called.
101.Pp
102The
103.Fn unlockpt
224c7076
A
104function unlocks the slave pseudo-terminal device associated
105with the master device to which
106.Fa fildes
107refers.
9385eb3d
A
108.Pp
109The
110.Fn posix_openpt
111function opens the first available master pseudo-terminal
112device and returns a descriptor to it.
3d9156a7 113The
224c7076 114.Fa oflag
3d9156a7 115argument
9385eb3d 116specifies the flags used for opening the device:
3d9156a7 117.Bl -tag -width ".Dv O_NOCTTY"
9385eb3d
A
118.It Dv O_RDWR
119Open for reading and writing.
120.It Dv O_NOCTTY
121If set, do not allow the terminal to become
122the controlling terminal for the calling process.
123.El
124.Sh RETURN VALUES
3d9156a7 125.Rv -std grantpt unlockpt
9385eb3d
A
126.Pp
127The
128.Fn ptsname
129function returns a pointer to the name
3d9156a7
A
130of the slave device on success; otherwise a
131.Dv NULL
132pointer is returned and the global variable
9385eb3d
A
133.Va errno
134is set to indicate the error.
135.Pp
136The
137.Fn posix_openpt
138function returns a file descriptor to the first
139available master pseudo-terminal device on success;
3d9156a7 140otherwise \-1 is returned and the global variable
9385eb3d
A
141.Va errno
142is set to indicate the error.
143.Sh ERRORS
144The
145.Fn grantpt ,
146.Fn ptsname ,
147and
148.Fn unlockpt
149functions may fail and set
150.Va errno
151to:
152.Bl -tag -width Er
3d9156a7
A
153.It Bq Er EINVAL
154.Fa fildes
9385eb3d
A
155is not a master pseudo-terminal device.
156.El
157.Pp
158In addition, the
159.Fn grantpt
160function may set
161.Va errno
162to:
163.Bl -tag -width Er
3d9156a7 164.It Bq Er EACCES
9385eb3d
A
165The slave pseudo-terminal device could not be accessed.
166.El
167.Pp
168The
169.Fn posix_openpt
170function may fail and set
171.Va errno
172to:
173.Bl -tag -width Er
3d9156a7 174.It Bq Er EINVAL
224c7076 175.Fa oflag
3d9156a7
A
176consists of an invalid mode bit.
177.It Bq Er EAGAIN
9385eb3d
A
178The system has no available pseudo-terminal devices.
179.El
180.Pp
181The
182.Fn grantpt ,
183.Fn ptsname ,
184and
185.Fn unlockpt
186functions may also fail and set
187.Va errno
3d9156a7
A
188for any of the errors specified for the
189.Xr fstat 2
190system call.
9385eb3d
A
191.Pp
192The
193.Fn posix_openpt
194function may also fail and set
195.Va errno
3d9156a7
A
196for any of the errors specified for the
197.Xr open 2
198system call.
224c7076
A
199.Sh LEGACY SYNOPSIS
200.Fd #include <stdlib.h>
201.Fd #include <fcntl.h>
202.Pp
203.Ft int
204.br
205.Fo grantpt
206.Fa "int fildes"
207.Fc ;
208.Pp
209.Ft "char *"
210.br
211.Fo ptsname
212.Fa "int fildes"
213.Fc ;
214.Pp
215.Ft int
216.br
217.Fo unlockpt
218.Fa "int fildes"
219.Fc ;
220.Pp
221.Fd #include <fcntl.h>
222.Pp
223.Ft int
224.br
225.Fo posix_openpt
226.Fa "int oflag"
227.Fc ;
9385eb3d
A
228.Sh SEE ALSO
229.Xr open 2 ,
230.Xr pty 4 ,
224c7076
A
231.Xr tty 4 ,
232.Xr compat 5
9385eb3d
A
233.Sh STANDARDS
234The
235.Fn grantpt ,
236.Fn ptsname ,
237.Fn unlockpt ,
238and
239.Fn posix_openpt
240functions conform to
241.St -p1003.1-2001 .