xref: /minix3/lib/libc/stdlib/ptsname.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\" $NetBSD: ptsname.3,v 1.9 2014/01/10 09:43:15 wiz Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
42fe8fb19SBen Gras.\" All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to The NetBSD Foundation
72fe8fb19SBen Gras.\" by Christos Zoulas.
82fe8fb19SBen Gras.\"
92fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
102fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
112fe8fb19SBen Gras.\" are met:
122fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
132fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
142fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
152fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
162fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
192fe8fb19SBen Gras.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
202fe8fb19SBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
212fe8fb19SBen Gras.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
222fe8fb19SBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232fe8fb19SBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242fe8fb19SBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252fe8fb19SBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262fe8fb19SBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272fe8fb19SBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282fe8fb19SBen Gras.\" POSSIBILITY OF SUCH DAMAGE.
292fe8fb19SBen Gras.\"
30*0a6a1f1dSLionel Sambuc.Dd January 7, 2014
312fe8fb19SBen Gras.Dt PTSNAME 3
322fe8fb19SBen Gras.Os
332fe8fb19SBen Gras.Sh NAME
34*0a6a1f1dSLionel Sambuc.Nm ptsname ,
35*0a6a1f1dSLionel Sambuc.Nm ptsname_r
362fe8fb19SBen Gras.Nd get the pathname of the slave pseudo-terminal device
372fe8fb19SBen Gras.Sh LIBRARY
382fe8fb19SBen Gras.Lb libc
392fe8fb19SBen Gras.Sh SYNOPSIS
402fe8fb19SBen Gras.In stdlib.h
412fe8fb19SBen Gras.Ft char *
422fe8fb19SBen Gras.Fn ptsname "int masterfd"
43*0a6a1f1dSLionel Sambuc.Ft char *
44*0a6a1f1dSLionel Sambuc.Fn ptsname_r "int masterfd" "char *buf" "size_t buflen"
452fe8fb19SBen Gras.Sh DESCRIPTION
462fe8fb19SBen GrasThe
472fe8fb19SBen Gras.Fn ptsname
482fe8fb19SBen Grasfunction returns the pathname of the slave pseudo-terminal device
492fe8fb19SBen Grasthat corresponds to the master pseudo-terminal device associated with
502fe8fb19SBen Gras.Fa masterfd .
512fe8fb19SBen GrasThe
522fe8fb19SBen Gras.Fn ptsname
532fe8fb19SBen Grasfunction is not reentrant or thread-safe.
54*0a6a1f1dSLionel Sambuc.Pp
55*0a6a1f1dSLionel SambucThe
56*0a6a1f1dSLionel Sambuc.Fn ptsname_r
57*0a6a1f1dSLionel Sambucfunction
58*0a6a1f1dSLionel Sambucplaces the pathname of the slave pseudo-terminal device that corresponds
59*0a6a1f1dSLionel Sambucto the master pseudo-terminal device associated with
60*0a6a1f1dSLionel Sambuc.Fa masterfd
61*0a6a1f1dSLionel Sambucint the
62*0a6a1f1dSLionel Sambuc.Fa buf
63*0a6a1f1dSLionel Sambucargument copying up to
64*0a6a1f1dSLionel Sambuc.Fa buflen
65*0a6a1f1dSLionel Sambuccharacters.
66*0a6a1f1dSLionel SambucThe
67*0a6a1f1dSLionel Sambuc.Fa buf
68*0a6a1f1dSLionel Sambucis always
69*0a6a1f1dSLionel Sambuc.Dv NUL
70*0a6a1f1dSLionel Sambucterminated.
712fe8fb19SBen Gras.Sh RETURN VALUES
722fe8fb19SBen GrasIf successful,
732fe8fb19SBen Gras.Fn ptsname
742fe8fb19SBen Grasreturns a pointer to a nul-terminated string containing the pathname
752fe8fb19SBen Grasof the slave pseudo-terminal device.
762fe8fb19SBen GrasIf an error occurs
772fe8fb19SBen Gras.Fn ptsname
782fe8fb19SBen Graswill return
792fe8fb19SBen Gras.Dv NULL
802fe8fb19SBen Grasand
812fe8fb19SBen Gras.Va errno
822fe8fb19SBen Grasis set to indicate the error.
83*0a6a1f1dSLionel Sambuc.Pp
84*0a6a1f1dSLionel SambucIf successful,
85*0a6a1f1dSLionel Sambuc.Fn ptsname_r
86*0a6a1f1dSLionel Sambucplaces a nul-terminated string containing the pathname
87*0a6a1f1dSLionel Sambucof the slave pseudo-terminal device
88*0a6a1f1dSLionel Sambucin
89*0a6a1f1dSLionel Sambuc.Fa buf
90*0a6a1f1dSLionel Sambucand returns
91*0a6a1f1dSLionel Sambuc.Dv 0 .
92*0a6a1f1dSLionel SambucIf an error occurs
93*0a6a1f1dSLionel Sambuc.Fn ptsname_r
94*0a6a1f1dSLionel Sambucwill return
95*0a6a1f1dSLionel Sambucan error number number indicating what went wrong.
962fe8fb19SBen Gras.Sh ERRORS
972fe8fb19SBen GrasThe
982fe8fb19SBen Gras.Fn ptsname
99*0a6a1f1dSLionel Sambucand
100*0a6a1f1dSLionel Sambuc.Fn ptsname_r
101*0a6a1f1dSLionel Sambucfunctions will fail if:
1022fe8fb19SBen Gras.Bl -tag -width Er
1032fe8fb19SBen Gras.It Bq Er EACCESS
1042fe8fb19SBen Grasthe corresponding pseudo-terminal device could not be accessed.
1052fe8fb19SBen Gras.It Bq Er EBADF
1062fe8fb19SBen Gras.Fa masterfd
1072fe8fb19SBen Grasis not a valid descriptor.
1082fe8fb19SBen Gras.It Bq Er EINVAL
1092fe8fb19SBen Gras.Fa masterfd
1102fe8fb19SBen Grasis not associated with a master pseudo-terminal device.
1112fe8fb19SBen Gras.El
112*0a6a1f1dSLionel Sambuc.Pp
113*0a6a1f1dSLionel SambucIn addition the
114*0a6a1f1dSLionel Sambuc.Fn ptsname_r
115*0a6a1f1dSLionel Sambucfunction
116*0a6a1f1dSLionel Sambucwill return:
117*0a6a1f1dSLionel Sambuc.Bl -tag -width Er
118*0a6a1f1dSLionel Sambuc.It Bq Er EINVAL
119*0a6a1f1dSLionel Sambucthe
120*0a6a1f1dSLionel Sambuc.Fa buf
121*0a6a1f1dSLionel Sambucargument is
122*0a6a1f1dSLionel Sambuc.Dv NULL .
123*0a6a1f1dSLionel Sambuc.It Bq Er ERANGE
124*0a6a1f1dSLionel Sambucthe name of the pseudo-terminal is longer than
125*0a6a1f1dSLionel Sambuc.Fa bufsiz
126*0a6a1f1dSLionel Sambuccharacters plus the terminating
127*0a6a1f1dSLionel Sambuc.Dv NUL .
128*0a6a1f1dSLionel Sambuc.El
1292fe8fb19SBen Gras.Sh NOTES
1302fe8fb19SBen GrasThe error returns of
1312fe8fb19SBen Gras.Fn ptsname
1322fe8fb19SBen Grasare a
1332fe8fb19SBen Gras.Nx
1342fe8fb19SBen Grasextension.
1352fe8fb19SBen GrasThe
1362fe8fb19SBen Gras.Fn ptsname
1372fe8fb19SBen Grasfunction is equivalent to:
1382fe8fb19SBen Gras.Bd -literal
1392fe8fb19SBen Gras	struct ptmget pm;
14084d9c625SLionel Sambuc	return ioctl(masterfd, TIOCPTSNAME, \*[Am]pm) == -1 ? NULL : pm.sn;
1412fe8fb19SBen Gras.Ed
142*0a6a1f1dSLionel Sambuc.Pp
143*0a6a1f1dSLionel SambucBoth the
144*0a6a1f1dSLionel Sambuc.Fn ptsname
145*0a6a1f1dSLionel Sambucand
146*0a6a1f1dSLionel Sambuc.Fn ptsname_r
147*0a6a1f1dSLionel Sambucfunctions will also return the name of the slave pseudo-terminal if a file
148*0a6a1f1dSLionel Sambucdescriptor to the slave pseudo-terminal is passed to
149*0a6a1f1dSLionel Sambuc.Fa masterfd .
150*0a6a1f1dSLionel Sambuc.Pp
151*0a6a1f1dSLionel SambucThis is a convenient extension because it allows one to use the file descriptor
152*0a6a1f1dSLionel Sambucobtained by
153*0a6a1f1dSLionel Sambuc.Xr open 2
154*0a6a1f1dSLionel Sambuc.Pa /dev/tty
155*0a6a1f1dSLionel Sambucto obtain the name of the pseudo-terminal for the current process.
1562fe8fb19SBen Gras.Sh SEE ALSO
1572fe8fb19SBen Gras.Xr ioctl 2 ,
158*0a6a1f1dSLionel Sambuc.Xr open 2 ,
1592fe8fb19SBen Gras.Xr grantpt 3 ,
1602fe8fb19SBen Gras.Xr posix_openpt 3 ,
1612fe8fb19SBen Gras.Xr unlockpt 3
1622fe8fb19SBen Gras.Sh STANDARDS
1632fe8fb19SBen GrasThe
1642fe8fb19SBen Gras.Fn ptsname
1652fe8fb19SBen Grasfunction conforms to
1662fe8fb19SBen Gras.St -p1003.1-2001 .
1672fe8fb19SBen GrasIts first release was in
1682fe8fb19SBen Gras.St -xpg4.2 .
169