1 .\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
24 .\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
25 .\" Added ttyname_r, aeb, 2002-07-20
27 .TH TTYNAME 3 2017-05-03 "Linux" "Linux Programmer's Manual"
29 ttyname, ttyname_r \- return name of a terminal
32 .B #include <unistd.h>
34 .BI "char *ttyname(int " fd );
36 .BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
41 returns a pointer to the null-terminated pathname of the terminal device
42 that is open on the file descriptor \fIfd\fP, or NULL on error
43 (for example, if \fIfd\fP is not connected to a terminal).
44 The return value may point to static data, possibly overwritten by the
48 stores this pathname in the buffer
55 returns a pointer to a pathname on success.
56 On error, NULL is returned, and
61 returns 0 on success, and an error number upon error.
68 File descriptor does not refer to a terminal device.
73 was too small to allow storing the pathname.
75 .\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
77 File descriptor refers to a slave pseudoterminal device
78 but the corresponding pathname could not be found (see NOTES).
80 For an explanation of the terms used in this section, see
86 Interface Attribute Value
89 T} Thread safety MT-Unsafe race:ttyname
92 T} Thread safety MT-Safe
95 POSIX.1-2001, POSIX.1-2008, 4.2BSD.
97 A process that keeps a file descriptor that refers to a
99 device open when switching to another mount namespace that uses a different
101 instance may still accidentally find that a device path of the same name
102 for that file descriptor exists.
103 However, this device path refers to a different device and thus
104 can't be used to access the device that the file descriptor refers to.
109 on the file descriptor in the new mount namespace will cause these
110 functions to return NULL and set