2 .\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
7 .\" Added ttyname_r, aeb, 2002-07-20
9 .TH ttyname 3 (date) "Linux man-pages (unreleased)"
11 ttyname, ttyname_r \- return name of a terminal
14 .RI ( libc ", " \-lc )
17 .B #include <unistd.h>
19 .BI "char *ttyname(int " fd );
20 .BI "int ttyname_r(int " fd ", char " buf [. buflen "], size_t " buflen );
25 returns a pointer to the null-terminated pathname of the terminal device
26 that is open on the file descriptor \fIfd\fP, or NULL on error
27 (for example, if \fIfd\fP is not connected to a terminal).
28 The return value may point to static data, possibly overwritten by the
32 stores this pathname in the buffer
39 returns a pointer to a pathname on success.
40 On error, NULL is returned, and
42 is set to indicate the error.
45 returns 0 on success, and an error number upon error.
51 .\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
54 refers to a slave pseudoterminal device
55 but the corresponding pathname could not be found (see NOTES).
59 does not refer to a terminal device.
64 was too small to allow storing the pathname.
66 For an explanation of the terms used in this section, see
72 Interface Attribute Value
77 T} Thread safety MT-Unsafe race:ttyname
82 T} Thread safety MT-Safe
89 A process that keeps a file descriptor that refers to a
91 device open when switching to another mount namespace that uses a different
93 instance may still accidentally find that a device path of the same name
94 for that file descriptor exists.
95 However, this device path refers to a different device and thus
96 can't be used to access the device that the file descriptor refers to.
101 on the file descriptor in the new mount namespace will cause these
102 functions to return NULL and set