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 2021-03-22 "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 );
35 .BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
40 returns a pointer to the null-terminated pathname of the terminal device
41 that is open on the file descriptor \fIfd\fP, or NULL on error
42 (for example, if \fIfd\fP is not connected to a terminal).
43 The return value may point to static data, possibly overwritten by the
47 stores this pathname in the buffer
54 returns a pointer to a pathname on success.
55 On error, NULL is returned, and
57 is set to indicate the error.
60 returns 0 on success, and an error number upon error.
66 .\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
69 refers to a slave pseudoterminal device
70 but the corresponding pathname could not be found (see NOTES).
74 does not refer to a terminal device.
79 was too small to allow storing the pathname.
81 For an explanation of the terms used in this section, see
89 Interface Attribute Value
92 T} Thread safety MT-Unsafe race:ttyname
95 T} Thread safety MT-Safe
101 POSIX.1-2001, POSIX.1-2008, 4.2BSD.
103 A process that keeps a file descriptor that refers to a
105 device open when switching to another mount namespace that uses a different
107 instance may still accidentally find that a device path of the same name
108 for that file descriptor exists.
109 However, this device path refers to a different device and thus
110 can't be used to access the device that the file descriptor refers to.
115 on the file descriptor in the new mount namespace will cause these
116 functions to return NULL and set