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