]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ttyname.3
7414843722b590c27eceb484843816ce6f2b9d77
[thirdparty/man-pages.git] / man3 / ttyname.3
1 .\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2 .\"
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.
8 .\"
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.
13 .\"
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.
18 .\"
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/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
25 .\" Added ttyname_r, aeb, 2002-07-20
26 .\"
27 .TH TTYNAME 3 2017-05-03 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 ttyname, ttyname_r \- return name of a terminal
30 .SH SYNOPSIS
31 .nf
32 .B #include <unistd.h>
33 .PP
34 .BI "char *ttyname(int " fd );
35 .PP
36 .BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
37 .fi
38 .SH DESCRIPTION
39 The function
40 .BR ttyname ()
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
45 next call.
46 The function
47 .BR ttyname_r ()
48 stores this pathname in the buffer
49 .I buf
50 of length
51 .IR buflen .
52 .SH RETURN VALUE
53 The function
54 .BR ttyname ()
55 returns a pointer to a pathname on success.
56 On error, NULL is returned, and
57 .I errno
58 is set appropriately.
59 The function
60 .BR ttyname_r ()
61 returns 0 on success, and an error number upon error.
62 .SH ERRORS
63 .TP
64 .B EBADF
65 Bad file descriptor.
66 .TP
67 .B ENOTTY
68 File descriptor does not refer to a terminal device.
69 .TP
70 .B ERANGE
71 .RB ( ttyname_r ())
72 .I buflen
73 was too small to allow storing the pathname.
74 .TP
75 .\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
76 .B ENODEV
77 File descriptor refers to a slave pseudoterminal device
78 but the corresponding pathname could not be found (see NOTES).
79 .SH ATTRIBUTES
80 For an explanation of the terms used in this section, see
81 .BR attributes (7).
82 .TS
83 allbox;
84 lb lb lb
85 l l l.
86 Interface Attribute Value
87 T{
88 .BR ttyname ()
89 T} Thread safety MT-Unsafe race:ttyname
90 T{
91 .BR ttyname_r ()
92 T} Thread safety MT-Safe
93 .TE
94 .SH CONFORMING TO
95 POSIX.1-2001, POSIX.1-2008, 4.2BSD.
96 .SH NOTES
97 A process that keeps a file descriptor that refers to a
98 .BR pts (4)
99 device open when switching to another mount namespace that uses a different
100 .IR /dev/ptmx
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.
105 Calling
106 .BR ttyname ()
107 or
108 .BR ttyname_r ()
109 on the file descriptor in the new mount namespace will cause these
110 functions to return NULL and set
111 .I errno
112 to
113 .BR ENODEV .
114 .SH SEE ALSO
115 .BR tty (1),
116 .BR fstat (2),
117 .BR ctermid (3),
118 .BR isatty (3),
119 .BR pts (4)