1 .\" $NetBSD: ttyname.3,v 1.21 2008/06/25 11:47:29 ad Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)ttyname.3 8.1 (Berkeley) 6/4/93
40 .Nd get name of associated terminal (tty) from file descriptor
48 .Fn ttyname_r "int fd" "char *buf" "size_t len"
55 These functions operate on the system file descriptors for terminal
57 These descriptors are not related to the standard
60 typedef, but refer to the special device files found in
64 and for which an entry exists in the initialization file
68 or for pseudo-terminal devices created in ptyfs and named
69 .Pa /dev/pts/ Ns Em n .
74 determines if the file descriptor
76 refers to a valid terminal type device.
80 function gets the related device name of a file descriptor for
86 is the reentrant version of the above, and it places the results in
88 If there is not enough space to place the results (indicated by
90 then it returns an error.
95 fetches the current process' control terminal number from the
98 If the terminal is a pseudo-terminal, and there is no special entry
101 file for it, the slot number returned is 1 + (last slot number) +
103 This will return a consistent and unique number for each pseudo-terminal
104 device without requiring one to enumerate all of them in
106 .Sh IMPLEMENTATION NOTES
107 As an optimisation, these functions attempt to obtain information about
110 database, if it exists.
111 If the database exists but is out of date, then these functions
112 may produce incorrect results.
113 The database should be updated using the
119 function returns the NUL-terminated name if the device is found and
124 pointer is returned and
126 is set to indicate the error.
130 functions returns 0 on success and an error code on failure.
134 function returns 1 if
136 is associated with a terminal device; otherwise it returns 0 and
138 is set to indicate the error.
143 returns the unit number of the device file if found; otherwise
144 the value zero is returned.
146 .Bl -tag -width /etc/ttys -compact
156 functions will fail if:
161 argument is not a valid file descriptor.
165 argument does not refer to a terminal device.
170 function will also fail if:
173 The buffer provided is not large enough to fit the result.
175 The terminal device is not found.
176 This can happen if the device node has been removed after it was opened.
194 functions appeared in
196 .\" Use of the .Pa /var/run/dev.db file was added in ???.
200 function leaves its result in an internal static object and returns
201 a pointer to that object.
204 will modify the same object.