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.\" 34*3e7224dfSXin LI.Dd October 17, 2020 35bc093719SEd Schouten.Dt PTSNAME 3 36aa12cea2SUlrich Spörlein.Os 37bc093719SEd Schouten.Sh NAME 38bc093719SEd Schouten.Nm grantpt , 39bc093719SEd Schouten.Nm ptsname , 40*3e7224dfSXin LI.Nm ptsname_r , 41bc093719SEd Schouten.Nm unlockpt 42bc093719SEd Schouten.Nd pseudo-terminal access functions 43bc093719SEd Schouten.Sh LIBRARY 44bc093719SEd Schouten.Lb libc 45bc093719SEd Schouten.Sh SYNOPSIS 46bc093719SEd Schouten.In stdlib.h 47bc093719SEd Schouten.Ft int 48bc093719SEd Schouten.Fn grantpt "int fildes" 49bc093719SEd Schouten.Ft "char *" 50bc093719SEd Schouten.Fn ptsname "int fildes" 51*3e7224dfSXin LI.Ft "int" 52*3e7224dfSXin LI.Fn ptsname_r "int fildes" "char *buffer" "size_t buflen" 53bc093719SEd Schouten.Ft int 54bc093719SEd Schouten.Fn unlockpt "int fildes" 55bc093719SEd Schouten.Sh DESCRIPTION 56bc093719SEd SchoutenThe 57bc093719SEd Schouten.Fn grantpt , 58bc093719SEd Schouten.Fn ptsname , 59bc093719SEd Schoutenand 60bc093719SEd Schouten.Fn unlockpt 61bc093719SEd Schoutenfunctions allow access to pseudo-terminal devices. 62bc093719SEd SchoutenThese three functions accept a file descriptor that references the 63bc093719SEd Schoutenmaster half of a pseudo-terminal pair. 64bc093719SEd SchoutenThis file descriptor is created with 65bc093719SEd Schouten.Xr posix_openpt 2 . 66bc093719SEd Schouten.Pp 67bc093719SEd SchoutenThe 68bc093719SEd Schouten.Fn grantpt 69bc093719SEd Schoutenfunction is used to establish ownership and permissions 70bc093719SEd Schoutenof the slave device counterpart to the master device 71bc093719SEd Schoutenspecified with 72bc093719SEd Schouten.Fa fildes . 73bc093719SEd SchoutenThe slave device's ownership is set to the real user ID 74bc093719SEd Schoutenof the calling process, and the permissions are set to 75bc093719SEd Schoutenuser readable-writable and group writable. 76bc093719SEd SchoutenThe group owner of the slave device is also set to the 77bc093719SEd Schoutengroup 78bc093719SEd Schouten.Dq Li tty . 79bc093719SEd Schouten.Pp 80bc093719SEd SchoutenThe 81bc093719SEd Schouten.Fn ptsname 82bc093719SEd Schoutenfunction returns the full pathname of the slave device 83bc093719SEd Schoutencounterpart to the master device specified with 84bc093719SEd Schouten.Fa fildes . 85bc093719SEd SchoutenThis value can be used 86bc093719SEd Schoutento subsequently open the appropriate slave after 87bc093719SEd Schouten.Xr posix_openpt 2 88bc093719SEd Schoutenand 89bc093719SEd Schouten.Fn grantpt 90bc093719SEd Schoutenhave been called. 91bc093719SEd Schouten.Pp 92bc093719SEd SchoutenThe 93*3e7224dfSXin LI.Fn ptsname_r 94*3e7224dfSXin LIfunction is the thread-safe version of 95*3e7224dfSXin LI.Fn ptsname . 96*3e7224dfSXin LIThe caller must provide storage for the results of the full pathname of 97*3e7224dfSXin LIthe slave device in the 98*3e7224dfSXin LI.Fa buffer 99*3e7224dfSXin LIand 100*3e7224dfSXin LI.Fa bufsize 101*3e7224dfSXin LIarguments. 102*3e7224dfSXin LI.Pp 103*3e7224dfSXin LIThe 104bc093719SEd Schouten.Fn unlockpt 105bc093719SEd Schoutenfunction clears the lock held on the pseudo-terminal pair 106bc093719SEd Schoutenfor the master device specified with 107bc093719SEd Schouten.Fa fildes . 108bc093719SEd Schouten.Sh RETURN VALUES 109*3e7224dfSXin LI.Rv -std grantpt ptsname_r unlockpt 110bc093719SEd Schouten.Pp 111bc093719SEd SchoutenThe 112bc093719SEd Schouten.Fn ptsname 113bc093719SEd Schoutenfunction returns a pointer to the name 114bc093719SEd Schoutenof the slave device on success; otherwise a 115bc093719SEd Schouten.Dv NULL 116bc093719SEd Schoutenpointer is returned. 117bc093719SEd Schouten.Sh ERRORS 118bc093719SEd SchoutenThe 1196cbb6bbbSEd Maste.Fn grantpt , 120*3e7224dfSXin LI.Fn ptsname , 121*3e7224dfSXin LI.Fn ptsname_r 122bc093719SEd Schoutenand 123bc093719SEd Schouten.Fn unlockpt 124bc093719SEd Schoutenfunctions may fail and set 125bc093719SEd Schouten.Va errno 126bc093719SEd Schoutento: 127bc093719SEd Schouten.Bl -tag -width Er 128bc093719SEd Schouten.It Bq Er EBADF 129bc093719SEd Schouten.Fa fildes 130bc093719SEd Schoutenis not a valid open file descriptor. 131bc093719SEd Schouten.It Bq Er EINVAL 132bc093719SEd Schouten.Fa fildes 133bc093719SEd Schoutenis not a master pseudo-terminal device. 134bc093719SEd Schouten.El 135bc093719SEd Schouten.Pp 136bc093719SEd SchoutenIn addition, the 137*3e7224dfSXin LI.Fn ptsname_r 138*3e7224dfSXin LIfunction may set 139*3e7224dfSXin LI.Va errno 140*3e7224dfSXin LIto: 141*3e7224dfSXin LI.Bl -tag -width Er 142*3e7224dfSXin LI.It Bq Er ERANGE 143*3e7224dfSXin LIThe buffer was too small. 144*3e7224dfSXin LI.El 145*3e7224dfSXin LI.Pp 146*3e7224dfSXin LIIn addition, the 147bc093719SEd Schouten.Fn grantpt 148bc093719SEd Schoutenfunction may set 149bc093719SEd Schouten.Va errno 150bc093719SEd Schoutento: 151bc093719SEd Schouten.Bl -tag -width Er 152bc093719SEd Schouten.It Bq Er EACCES 153bc093719SEd SchoutenThe slave pseudo-terminal device could not be accessed. 154bc093719SEd Schouten.El 155bc093719SEd Schouten.Sh SEE ALSO 156bc093719SEd Schouten.Xr posix_openpt 2 , 157bc093719SEd Schouten.Xr pts 4 , 158bc093719SEd Schouten.Xr tty 4 159bc093719SEd Schouten.Sh STANDARDS 160bc093719SEd SchoutenThe 161bc093719SEd Schouten.Fn ptsname 16298669c79SEd Schoutenfunction conforms to 16300ee13a0SEd Schouten.St -p1003.1-2008 . 16498669c79SEd Schouten.Pp 16598669c79SEd SchoutenThis implementation of 16698669c79SEd Schouten.Fn grantpt 167bc093719SEd Schoutenand 168bc093719SEd Schouten.Fn unlockpt 16900ee13a0SEd Schoutendoes not conform to 17000ee13a0SEd Schouten.St -p1003.1-2008 , 17100ee13a0SEd Schoutenbecause it depends on 17200ee13a0SEd Schouten.Xr posix_openpt 2 17300ee13a0SEd Schoutento create the pseudo-terminal device with proper permissions in place. 17400ee13a0SEd SchoutenIt only validates whether 17500ee13a0SEd Schouten.Fa fildes 17600ee13a0SEd Schoutenis a valid pseudo-terminal master device. 17700ee13a0SEd SchoutenFuture revisions of the specification will likely allow this behaviour, 17800ee13a0SEd Schoutenas stated by the Austin Group. 179bc093719SEd Schouten.Sh HISTORY 180bc093719SEd SchoutenThe 181bc093719SEd Schouten.Fn grantpt , 182bc093719SEd Schouten.Fn ptsname 183bc093719SEd Schoutenand 184bc093719SEd Schouten.Fn unlockpt 185bc093719SEd Schoutenfunctions appeared in 186bc093719SEd Schouten.Fx 5.0 . 187