xref: /freebsd/lib/libc/stdlib/ptsname.3 (revision 6cbb6bbb7761bc8545860d105b9e4aea1f74c33f)
1bc093719SEd Schouten.\"
2bc093719SEd Schouten.\" Copyright (c) 2002 The FreeBSD Project, Inc.
3bc093719SEd Schouten.\" All rights reserved.
4bc093719SEd Schouten.\"
5bc093719SEd Schouten.\" This software includes code contributed to the FreeBSD Project
6bc093719SEd Schouten.\" by Ryan Younce of North Carolina State University.
7bc093719SEd Schouten.\"
8bc093719SEd Schouten.\" Redistribution and use in source and binary forms, with or without
9bc093719SEd Schouten.\" modification, are permitted provided that the following conditions
10bc093719SEd Schouten.\" are met:
11bc093719SEd Schouten.\" 1. Redistributions of source code must retain the above copyright
12bc093719SEd Schouten.\"    notice, this list of conditions and the following disclaimer.
13bc093719SEd Schouten.\" 2. Redistributions in binary form must reproduce the above copyright
14bc093719SEd Schouten.\"    notice, this list of conditions and the following disclaimer in the
15bc093719SEd Schouten.\"    documentation and/or other materials provided with the distribution.
16bc093719SEd Schouten.\" 3. Neither the name of the FreeBSD Project nor the names of its
17bc093719SEd Schouten.\"    contributors may be used to endorse or promote products derived from
18bc093719SEd Schouten.\"    this software without specific prior written permission.
19bc093719SEd Schouten.\"
20bc093719SEd Schouten.\" THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT AND CONTRIBUTORS
21bc093719SEd Schouten.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22bc093719SEd Schouten.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23bc093719SEd Schouten.\" PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FREEBSD PROJECT
24bc093719SEd Schouten.\" OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25bc093719SEd Schouten.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26bc093719SEd Schouten.\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27bc093719SEd Schouten.\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28bc093719SEd Schouten.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29bc093719SEd Schouten.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30bc093719SEd Schouten.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31bc093719SEd Schouten.\"
32bc093719SEd Schouten.\" $FreeBSD$
33bc093719SEd Schouten.\"
34bc093719SEd Schouten.Dd August 20, 2008
35bc093719SEd Schouten.Dt PTSNAME 3
36aa12cea2SUlrich Spörlein.Os
37bc093719SEd Schouten.Sh NAME
38bc093719SEd Schouten.Nm grantpt ,
39bc093719SEd Schouten.Nm ptsname ,
40bc093719SEd Schouten.Nm unlockpt
41bc093719SEd Schouten.Nd pseudo-terminal access functions
42bc093719SEd Schouten.Sh LIBRARY
43bc093719SEd Schouten.Lb libc
44bc093719SEd Schouten.Sh SYNOPSIS
45bc093719SEd Schouten.In stdlib.h
46bc093719SEd Schouten.Ft int
47bc093719SEd Schouten.Fn grantpt "int fildes"
48bc093719SEd Schouten.Ft "char *"
49bc093719SEd Schouten.Fn ptsname "int fildes"
50bc093719SEd Schouten.Ft int
51bc093719SEd Schouten.Fn unlockpt "int fildes"
52bc093719SEd Schouten.Sh DESCRIPTION
53bc093719SEd SchoutenThe
54bc093719SEd Schouten.Fn grantpt ,
55bc093719SEd Schouten.Fn ptsname ,
56bc093719SEd Schoutenand
57bc093719SEd Schouten.Fn unlockpt
58bc093719SEd Schoutenfunctions allow access to pseudo-terminal devices.
59bc093719SEd SchoutenThese three functions accept a file descriptor that references the
60bc093719SEd Schoutenmaster half of a pseudo-terminal pair.
61bc093719SEd SchoutenThis file descriptor is created with
62bc093719SEd Schouten.Xr posix_openpt 2 .
63bc093719SEd Schouten.Pp
64bc093719SEd SchoutenThe
65bc093719SEd Schouten.Fn grantpt
66bc093719SEd Schoutenfunction is used to establish ownership and permissions
67bc093719SEd Schoutenof the slave device counterpart to the master device
68bc093719SEd Schoutenspecified with
69bc093719SEd Schouten.Fa fildes .
70bc093719SEd SchoutenThe slave device's ownership is set to the real user ID
71bc093719SEd Schoutenof the calling process, and the permissions are set to
72bc093719SEd Schoutenuser readable-writable and group writable.
73bc093719SEd SchoutenThe group owner of the slave device is also set to the
74bc093719SEd Schoutengroup
75bc093719SEd Schouten.Dq Li tty .
76bc093719SEd Schouten.Pp
77bc093719SEd SchoutenThe
78bc093719SEd Schouten.Fn ptsname
79bc093719SEd Schoutenfunction returns the full pathname of the slave device
80bc093719SEd Schoutencounterpart to the master device specified with
81bc093719SEd Schouten.Fa fildes .
82bc093719SEd SchoutenThis value can be used
83bc093719SEd Schoutento subsequently open the appropriate slave after
84bc093719SEd Schouten.Xr posix_openpt 2
85bc093719SEd Schoutenand
86bc093719SEd Schouten.Fn grantpt
87bc093719SEd Schoutenhave been called.
88bc093719SEd Schouten.Pp
89bc093719SEd SchoutenThe
90bc093719SEd Schouten.Fn unlockpt
91bc093719SEd Schoutenfunction clears the lock held on the pseudo-terminal pair
92bc093719SEd Schoutenfor the master device specified with
93bc093719SEd Schouten.Fa fildes .
94bc093719SEd Schouten.Sh RETURN VALUES
95bc093719SEd Schouten.Rv -std grantpt unlockpt
96bc093719SEd Schouten.Pp
97bc093719SEd SchoutenThe
98bc093719SEd Schouten.Fn ptsname
99bc093719SEd Schoutenfunction returns a pointer to the name
100bc093719SEd Schoutenof the slave device on success; otherwise a
101bc093719SEd Schouten.Dv NULL
102bc093719SEd Schoutenpointer is returned.
103bc093719SEd Schouten.Sh ERRORS
104bc093719SEd SchoutenThe
105*6cbb6bbbSEd Maste.Fn grantpt ,
106*6cbb6bbbSEd Maste.Fn ptsname
107bc093719SEd Schoutenand
108bc093719SEd Schouten.Fn unlockpt
109bc093719SEd Schoutenfunctions may fail and set
110bc093719SEd Schouten.Va errno
111bc093719SEd Schoutento:
112bc093719SEd Schouten.Bl -tag -width Er
113bc093719SEd Schouten.It Bq Er EBADF
114bc093719SEd Schouten.Fa fildes
115bc093719SEd Schoutenis not a valid open file descriptor.
116bc093719SEd Schouten.It Bq Er EINVAL
117bc093719SEd Schouten.Fa fildes
118bc093719SEd Schoutenis not a master pseudo-terminal device.
119bc093719SEd Schouten.El
120bc093719SEd Schouten.Pp
121bc093719SEd SchoutenIn addition, the
122bc093719SEd Schouten.Fn grantpt
123bc093719SEd Schoutenfunction may set
124bc093719SEd Schouten.Va errno
125bc093719SEd Schoutento:
126bc093719SEd Schouten.Bl -tag -width Er
127bc093719SEd Schouten.It Bq Er EACCES
128bc093719SEd SchoutenThe slave pseudo-terminal device could not be accessed.
129bc093719SEd Schouten.El
130bc093719SEd Schouten.Sh SEE ALSO
131bc093719SEd Schouten.Xr posix_openpt 2 ,
132bc093719SEd Schouten.Xr pts 4 ,
133bc093719SEd Schouten.Xr tty 4
134bc093719SEd Schouten.Sh STANDARDS
135bc093719SEd SchoutenThe
136bc093719SEd Schouten.Fn ptsname
13798669c79SEd Schoutenfunction conforms to
13800ee13a0SEd Schouten.St -p1003.1-2008 .
13998669c79SEd Schouten.Pp
14098669c79SEd SchoutenThis implementation of
14198669c79SEd Schouten.Fn grantpt
142bc093719SEd Schoutenand
143bc093719SEd Schouten.Fn unlockpt
14400ee13a0SEd Schoutendoes not conform to
14500ee13a0SEd Schouten.St -p1003.1-2008 ,
14600ee13a0SEd Schoutenbecause it depends on
14700ee13a0SEd Schouten.Xr posix_openpt 2
14800ee13a0SEd Schoutento create the pseudo-terminal device with proper permissions in place.
14900ee13a0SEd SchoutenIt only validates whether
15000ee13a0SEd Schouten.Fa fildes
15100ee13a0SEd Schoutenis a valid pseudo-terminal master device.
15200ee13a0SEd SchoutenFuture revisions of the specification will likely allow this behaviour,
15300ee13a0SEd Schoutenas stated by the Austin Group.
154bc093719SEd Schouten.Sh HISTORY
155bc093719SEd SchoutenThe
156bc093719SEd Schouten.Fn grantpt ,
157bc093719SEd Schouten.Fn ptsname
158bc093719SEd Schoutenand
159bc093719SEd Schouten.Fn unlockpt
160bc093719SEd Schoutenfunctions appeared in
161bc093719SEd Schouten.Fx 5.0 .
162