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.\" 32*a5ed6a81SEd Maste.Dd October 14, 2023 33bc093719SEd Schouten.Dt PTSNAME 3 34aa12cea2SUlrich Spörlein.Os 35bc093719SEd Schouten.Sh NAME 36bc093719SEd Schouten.Nm grantpt , 37bc093719SEd Schouten.Nm ptsname , 383e7224dfSXin LI.Nm ptsname_r , 39bc093719SEd Schouten.Nm unlockpt 40bc093719SEd Schouten.Nd pseudo-terminal access functions 41bc093719SEd Schouten.Sh LIBRARY 42bc093719SEd Schouten.Lb libc 43bc093719SEd Schouten.Sh SYNOPSIS 44bc093719SEd Schouten.In stdlib.h 45bc093719SEd Schouten.Ft int 46bc093719SEd Schouten.Fn grantpt "int fildes" 47bc093719SEd Schouten.Ft "char *" 48bc093719SEd Schouten.Fn ptsname "int fildes" 493e7224dfSXin LI.Ft "int" 503e7224dfSXin LI.Fn ptsname_r "int fildes" "char *buffer" "size_t buflen" 51bc093719SEd Schouten.Ft int 52bc093719SEd Schouten.Fn unlockpt "int fildes" 53bc093719SEd Schouten.Sh DESCRIPTION 54bc093719SEd SchoutenThe 55bc093719SEd Schouten.Fn grantpt , 56bc093719SEd Schouten.Fn ptsname , 57bc093719SEd Schoutenand 58bc093719SEd Schouten.Fn unlockpt 59bc093719SEd Schoutenfunctions allow access to pseudo-terminal devices. 60bc093719SEd SchoutenThese three functions accept a file descriptor that references the 61bc093719SEd Schoutenmaster half of a pseudo-terminal pair. 62bc093719SEd SchoutenThis file descriptor is created with 63bc093719SEd Schouten.Xr posix_openpt 2 . 64bc093719SEd Schouten.Pp 65bc093719SEd SchoutenThe 66bc093719SEd Schouten.Fn grantpt 67bc093719SEd Schoutenfunction is used to establish ownership and permissions 68bc093719SEd Schoutenof the slave device counterpart to the master device 69bc093719SEd Schoutenspecified with 70bc093719SEd Schouten.Fa fildes . 71bc093719SEd SchoutenThe slave device's ownership is set to the real user ID 72bc093719SEd Schoutenof the calling process, and the permissions are set to 73bc093719SEd Schoutenuser readable-writable and group writable. 74bc093719SEd SchoutenThe group owner of the slave device is also set to the 75bc093719SEd Schoutengroup 76bc093719SEd Schouten.Dq Li tty . 77bc093719SEd Schouten.Pp 78bc093719SEd SchoutenThe 79bc093719SEd Schouten.Fn ptsname 80bc093719SEd Schoutenfunction returns the full pathname of the slave device 81bc093719SEd Schoutencounterpart to the master device specified with 82bc093719SEd Schouten.Fa fildes . 83bc093719SEd SchoutenThis value can be used 84bc093719SEd Schoutento subsequently open the appropriate slave after 85bc093719SEd Schouten.Xr posix_openpt 2 86bc093719SEd Schoutenand 87bc093719SEd Schouten.Fn grantpt 88bc093719SEd Schoutenhave been called. 89bc093719SEd Schouten.Pp 90bc093719SEd SchoutenThe 913e7224dfSXin LI.Fn ptsname_r 923e7224dfSXin LIfunction is the thread-safe version of 933e7224dfSXin LI.Fn ptsname . 943e7224dfSXin LIThe caller must provide storage for the results of the full pathname of 953e7224dfSXin LIthe slave device in the 963e7224dfSXin LI.Fa buffer 973e7224dfSXin LIand 983e7224dfSXin LI.Fa bufsize 993e7224dfSXin LIarguments. 1003e7224dfSXin LI.Pp 1013e7224dfSXin LIThe 102bc093719SEd Schouten.Fn unlockpt 103bc093719SEd Schoutenfunction clears the lock held on the pseudo-terminal pair 104bc093719SEd Schoutenfor the master device specified with 105bc093719SEd Schouten.Fa fildes . 106bc093719SEd Schouten.Sh RETURN VALUES 107*a5ed6a81SEd Maste.Rv -std grantpt unlockpt 108bc093719SEd Schouten.Pp 109bc093719SEd SchoutenThe 110bc093719SEd Schouten.Fn ptsname 111bc093719SEd Schoutenfunction returns a pointer to the name 112bc093719SEd Schoutenof the slave device on success; otherwise a 113bc093719SEd Schouten.Dv NULL 114bc093719SEd Schoutenpointer is returned. 115*a5ed6a81SEd Maste.Pp 116*a5ed6a81SEd MasteThe 117*a5ed6a81SEd Maste.Fn ptsname_r 118*a5ed6a81SEd Mastefunction returns the value 0 if successful; 119*a5ed6a81SEd Masteotherwise a nonzero value is returned and the global variable 120*a5ed6a81SEd Maste.Va errno 121*a5ed6a81SEd Masteis set to indicate the error. 122*a5ed6a81SEd MasteNote: 123*a5ed6a81SEd Maste.Fn ptsname_r 124*a5ed6a81SEd Mastewas previously documented as returning -1 on error. 125*a5ed6a81SEd MasteIn the future it will be changed to return an error number, for POSIX 126*a5ed6a81SEd Mastecompatibility. 127*a5ed6a81SEd MasteTherefore, callers should not check for -1. 128bc093719SEd Schouten.Sh ERRORS 129bc093719SEd SchoutenThe 1306cbb6bbbSEd Maste.Fn grantpt , 1313e7224dfSXin LI.Fn ptsname , 1323e7224dfSXin LI.Fn ptsname_r 133bc093719SEd Schoutenand 134bc093719SEd Schouten.Fn unlockpt 135bc093719SEd Schoutenfunctions may fail and set 136bc093719SEd Schouten.Va errno 137bc093719SEd Schoutento: 138bc093719SEd Schouten.Bl -tag -width Er 139bc093719SEd Schouten.It Bq Er EBADF 140bc093719SEd Schouten.Fa fildes 141bc093719SEd Schoutenis not a valid open file descriptor. 142bc093719SEd Schouten.It Bq Er EINVAL 143bc093719SEd Schouten.Fa fildes 144bc093719SEd Schoutenis not a master pseudo-terminal device. 145bc093719SEd Schouten.El 146bc093719SEd Schouten.Pp 147bc093719SEd SchoutenIn addition, the 1483e7224dfSXin LI.Fn ptsname_r 1493e7224dfSXin LIfunction may set 1503e7224dfSXin LI.Va errno 1513e7224dfSXin LIto: 1523e7224dfSXin LI.Bl -tag -width Er 1533e7224dfSXin LI.It Bq Er ERANGE 1543e7224dfSXin LIThe buffer was too small. 1553e7224dfSXin LI.El 1563e7224dfSXin LI.Pp 1573e7224dfSXin LIIn addition, the 158bc093719SEd Schouten.Fn grantpt 159bc093719SEd Schoutenfunction may set 160bc093719SEd Schouten.Va errno 161bc093719SEd Schoutento: 162bc093719SEd Schouten.Bl -tag -width Er 163bc093719SEd Schouten.It Bq Er EACCES 164bc093719SEd SchoutenThe slave pseudo-terminal device could not be accessed. 165bc093719SEd Schouten.El 166bc093719SEd Schouten.Sh SEE ALSO 167bc093719SEd Schouten.Xr posix_openpt 2 , 168bc093719SEd Schouten.Xr pts 4 , 169bc093719SEd Schouten.Xr tty 4 170bc093719SEd Schouten.Sh STANDARDS 171bc093719SEd SchoutenThe 172bc093719SEd Schouten.Fn ptsname 17398669c79SEd Schoutenfunction conforms to 17400ee13a0SEd Schouten.St -p1003.1-2008 . 17598669c79SEd Schouten.Pp 17698669c79SEd SchoutenThis implementation of 17798669c79SEd Schouten.Fn grantpt 178bc093719SEd Schoutenand 179bc093719SEd Schouten.Fn unlockpt 18000ee13a0SEd Schoutendoes not conform to 18100ee13a0SEd Schouten.St -p1003.1-2008 , 18200ee13a0SEd Schoutenbecause it depends on 18300ee13a0SEd Schouten.Xr posix_openpt 2 18400ee13a0SEd Schoutento create the pseudo-terminal device with proper permissions in place. 18500ee13a0SEd SchoutenIt only validates whether 18600ee13a0SEd Schouten.Fa fildes 18700ee13a0SEd Schoutenis a valid pseudo-terminal master device. 18800ee13a0SEd SchoutenFuture revisions of the specification will likely allow this behaviour, 18900ee13a0SEd Schoutenas stated by the Austin Group. 190bc093719SEd Schouten.Sh HISTORY 191bc093719SEd SchoutenThe 192bc093719SEd Schouten.Fn grantpt , 193bc093719SEd Schouten.Fn ptsname 194bc093719SEd Schoutenand 195bc093719SEd Schouten.Fn unlockpt 196bc093719SEd Schoutenfunctions appeared in 197bc093719SEd Schouten.Fx 5.0 . 198