166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 4366492cf0SYuri Pankov.\" Copyright 1989 AT&T 4466492cf0SYuri Pankov.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved 4566492cf0SYuri Pankov.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved. 46*8b913f79SRobert Mustacchi.\" Copyright 2024 Oxide Computer Company 4766492cf0SYuri Pankov.\" 48*8b913f79SRobert Mustacchi.Dd July 2, 2024 491fa2a664SJoshua M. Clulow.Dt PTSNAME 3C 501fa2a664SJoshua M. Clulow.Os 511fa2a664SJoshua M. Clulow.Sh NAME 52*8b913f79SRobert Mustacchi.Nm ptsname , 53*8b913f79SRobert Mustacchi.Nm ptsname_r 541fa2a664SJoshua M. Clulow.Nd get the name of the subsidiary device of a pseudo-terminal 551fa2a664SJoshua M. Clulow.Sh SYNOPSIS 561fa2a664SJoshua M. Clulow.In stdlib.h 571fa2a664SJoshua M. Clulow.Ft char * 581fa2a664SJoshua M. Clulow.Fo ptsname 591fa2a664SJoshua M. Clulow.Fa "int fildes" 601fa2a664SJoshua M. Clulow.Fc 61*8b913f79SRobert Mustacchi.Ft int 62*8b913f79SRobert Mustacchi.Fo ptsname_r 63*8b913f79SRobert Mustacchi.Fa "int fildes" 64*8b913f79SRobert Mustacchi.Fa "char *name" 65*8b913f79SRobert Mustacchi.Fa "size_t namelen" 66*8b913f79SRobert Mustacchi.Fc 671fa2a664SJoshua M. Clulow.Sh DESCRIPTION 681fa2a664SJoshua M. ClulowThe 691fa2a664SJoshua M. Clulow.Fn ptsname 701fa2a664SJoshua M. Clulowfunction returns the name of the pseudo-terminal subsidiary device associated 711fa2a664SJoshua M. Clulowwith a pseudo-terminal manager device. 721fa2a664SJoshua M. ClulowThe 731fa2a664SJoshua M. Clulow.Fa fildes 741fa2a664SJoshua M. Clulowargument is a file descriptor returned from a successful open of the 751fa2a664SJoshua M. Clulowpseudo-terminal manager device; e.g., by calling 761fa2a664SJoshua M. Clulow.Xr posix_openpt 3C 771fa2a664SJoshua M. Clulowor by performing an 781fa2a664SJoshua M. Clulow.Xr open 2 791fa2a664SJoshua M. Clulowof the 80bbf21555SRichard Lowe.Xr ptm 4D 811fa2a664SJoshua M. Clulowdevice. 821fa2a664SJoshua M. Clulow.Pp 831fa2a664SJoshua M. ClulowThe 841fa2a664SJoshua M. Clulow.Fn ptsname 851fa2a664SJoshua M. Clulowfunction returns a pointer to a string containing the null-terminated 861fa2a664SJoshua M. Clulowpath name of the subsidiary device. 871fa2a664SJoshua M. ClulowThis string is of the form 881fa2a664SJoshua M. Clulow.Pa /dev/pts/N , 891fa2a664SJoshua M. Clulowwhere 901fa2a664SJoshua M. Clulow.Sy N 911fa2a664SJoshua M. Clulowis a non-negative integer. 92*8b913f79SRobert MustacchiCallers should generally assume that a subsequent call to 93*8b913f79SRobert Mustacchi.Fn ptsname 94*8b913f79SRobert Mustacchiwill overwrite the returned buffer. 95*8b913f79SRobert MustacchiPOSIX does not require that the interface be thread-safe. 96*8b913f79SRobert MustacchiWhile a per-thread buffer is currently being used, that should not be relied 97*8b913f79SRobert Mustacchiupon by portable applications and is not a system guarantee. 98*8b913f79SRobert Mustacchi.Pp 99*8b913f79SRobert MustacchiThe 100*8b913f79SRobert Mustacchi.Fn ptsname_r 101*8b913f79SRobert Mustacchifunction behaves similarly to the 102*8b913f79SRobert Mustacchi.Fn ptsname 103*8b913f79SRobert Mustacchifunction, but rather than use a thread-specific buffer, stores the name of the 104*8b913f79SRobert Mustacchipseudo-terminal subsidiary device of 105*8b913f79SRobert Mustacchi.Fa fildes 106*8b913f79SRobert Mustacchiin 107*8b913f79SRobert Mustacchi.Fa name . 108*8b913f79SRobert MustacchiThe size of 109*8b913f79SRobert Mustacchi.Fa name 110*8b913f79SRobert Mustacchiis indicated by 111*8b913f79SRobert Mustacchi.Fa namelen . 112*8b913f79SRobert MustacchiIf the buffer is not large enough, then the function will fail with 113*8b913f79SRobert Mustacchi.Er ERANGE . 114*8b913f79SRobert MustacchiThe name's length will not exceed 115*8b913f79SRobert Mustacchi.Brq TTY_NAME_MAX , 116*8b913f79SRobert Mustacchiwhich can be determined at runtime by calling 117*8b913f79SRobert Mustacchi.Xr sysconf 3C 118*8b913f79SRobert Mustacchiwith the name 119*8b913f79SRobert Mustacchi.Dv _SC_TTY_NAME_MAX . 1201fa2a664SJoshua M. Clulow.Sh RETURN VALUES 121*8b913f79SRobert MustacchiUpon successful completion, the 1221fa2a664SJoshua M. Clulow.Fn ptsname 1231fa2a664SJoshua M. Clulowfunction returns a pointer to a string which is the name of the pseudo-terminal 1241fa2a664SJoshua M. Clulowsubsidiary device. 1251fa2a664SJoshua M. ClulowThis value points to a static data area that is overwritten by each call to 1261fa2a664SJoshua M. Clulow.Fn ptsname 127*8b913f79SRobert Mustacchiby the same thread. 128*8b913f79SRobert MustacchiOtherwise, 129*8b913f79SRobert Mustacchi.Dv NULL 130*8b913f79SRobert Mustacchiis returned and 131*8b913f79SRobert Mustacchi.Va errno 132*8b913f79SRobert Mustacchiis set to indicate the error that occurred. 133*8b913f79SRobert Mustacchi.Pp 134*8b913f79SRobert MustacchiUpon successful completion, the 135*8b913f79SRobert Mustacchi.Fn ptsname_r 136*8b913f79SRobert Mustacchifunction will return 137*8b913f79SRobert Mustacchi.Sy 0 138*8b913f79SRobert Mustacchiand 139*8b913f79SRobert Mustacchi.Fa name 140*8b913f79SRobert Mustacchiwill be filled in with the subsidiary device's name. 141*8b913f79SRobert MustacchiOtherwise, an error number will be returned. 142*8b913f79SRobert Mustacchi.Sh ERRORS 143*8b913f79SRobert MustacchiThe 144*8b913f79SRobert Mustacchi.Fn ptsname 145*8b913f79SRobert Mustacchiand 146*8b913f79SRobert Mustacchi.Fn ptsname_r 147*8b913f79SRobert Mustacchifunctions will fail if: 148*8b913f79SRobert Mustacchi.Bl -tag -width Er 149*8b913f79SRobert Mustacchi.It Er EBADF 150*8b913f79SRobert MustacchiThe file descriptor, 151*8b913f79SRobert Mustacchi.Fa fildes , 152*8b913f79SRobert Mustacchidoes not refer to a valid file descriptor. 153*8b913f79SRobert Mustacchi.It Er EINVAL 154*8b913f79SRobert MustacchiThe file descriptor, 155*8b913f79SRobert Mustacchi.Fa fildes , 156*8b913f79SRobert Mustacchidoes not refer to a manager pseudo-terminal device. 157*8b913f79SRobert Mustacchi.Pp 158*8b913f79SRobert MustacchiFor the 159*8b913f79SRobert Mustacchi.Fn ptsname_r 160*8b913f79SRobert Mustacchifunction, 161*8b913f79SRobert Mustacchi.Fa name 162*8b913f79SRobert Mustacchiis a 163*8b913f79SRobert Mustacchi.Dv NULL 164*8b913f79SRobert Mustacchipointer. 165*8b913f79SRobert Mustacchi.It Er ENOTTY 166*8b913f79SRobert MustacchiThe file descriptor, 167*8b913f79SRobert Mustacchi.Fa fildes , 168*8b913f79SRobert Mustacchidoes not refer to a manager pseudo-terminal device. 169*8b913f79SRobert Mustacchi.It Er ERANGE 170*8b913f79SRobert MustacchiFor the 171*8b913f79SRobert Mustacchi.Fn ptsname_r 172*8b913f79SRobert Mustacchifunction, the buffer 173*8b913f79SRobert Mustacchi.Fa name 's 174*8b913f79SRobert Mustacchisize as indicated by 175*8b913f79SRobert Mustacchi.Fa namelen 176*8b913f79SRobert Mustacchiwas too small to hold the actual subsidiary device's name. 177*8b913f79SRobert Mustacchi.El 1781fa2a664SJoshua M. Clulow.Sh INTERFACE STABILITY 1791fa2a664SJoshua M. Clulow.Sy Committed 1801fa2a664SJoshua M. Clulow.Sh MT LEVEL 181*8b913f79SRobert MustacchiThe 182*8b913f79SRobert Mustacchi.Fn ptsname 183*8b913f79SRobert Mustacchifunction is 184*8b913f79SRobert Mustacchi.Sy Safe . 185*8b913f79SRobert Mustacchi.Pp 186*8b913f79SRobert MustacchiThe 187*8b913f79SRobert Mustacchi.Fn ptsname_r 188*8b913f79SRobert Mustacchifunction is 189*8b913f79SRobert Mustacchi.Sy MT-Safe . 1901fa2a664SJoshua M. Clulow.Sh SEE ALSO 1911fa2a664SJoshua M. Clulow.Xr open 2 , 1921fa2a664SJoshua M. Clulow.Xr grantpt 3C , 1931fa2a664SJoshua M. Clulow.Xr posix_openpt 3C , 1941fa2a664SJoshua M. Clulow.Xr ttyname 3C , 1951fa2a664SJoshua M. Clulow.Xr unlockpt 3C , 196bbf21555SRichard Lowe.Xr ptm 4D , 197bbf21555SRichard Lowe.Xr pts 4D , 198bbf21555SRichard Lowe.Xr attributes 7 , 199bbf21555SRichard Lowe.Xr standards 7 200