]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/ttyname.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / ttyname.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2.\"
1dd72f9c 3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
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
c715f741
MK
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
6a8d8745 22.\" %%%LICENSE_END
c13182ef 23.\"
fea681da
MK
24.\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
25.\" Added ttyname_r, aeb, 2002-07-20
26.\"
867c9b34 27.TH TTYNAME 3 2019-10-10 "Linux" "Linux Programmer's Manual"
fea681da
MK
28.SH NAME
29ttyname, ttyname_r \- return name of a terminal
30.SH SYNOPSIS
31.nf
32.B #include <unistd.h>
68e4db0a 33.PP
fea681da 34.BI "char *ttyname(int " fd );
dbfe9c70 35.PP
fea681da
MK
36.BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
37.fi
38.SH DESCRIPTION
39The function
40.BR ttyname ()
28d88c17 41returns a pointer to the null-terminated pathname of the terminal device
35e21ba7 42that is open on the file descriptor \fIfd\fP, or NULL on error
fea681da
MK
43(for example, if \fIfd\fP is not connected to a terminal).
44The return value may point to static data, possibly overwritten by the
45next call.
46The function
47.BR ttyname_r ()
48stores this pathname in the buffer
49.I buf
50of length
51.IR buflen .
47297adb 52.SH RETURN VALUE
fea681da
MK
53The function
54.BR ttyname ()
c13182ef 55returns a pointer to a pathname on success.
8478ee02 56On error, NULL is returned, and
fea681da
MK
57.I errno
58is set appropriately.
59The function
60.BR ttyname_r ()
61returns 0 on success, and an error number upon error.
62.SH ERRORS
fea681da
MK
63.TP
64.B EBADF
65Bad file descriptor.
66.TP
49a2a105
MK
67.\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
68.B ENODEV
69File descriptor refers to a slave pseudoterminal device
70but the corresponding pathname could not be found (see NOTES).
71.TP
fea681da
MK
72.B ENOTTY
73File descriptor does not refer to a terminal device.
74.TP
75.B ERANGE
4bcf0534 76.RB ( ttyname_r ())
fea681da
MK
77.I buflen
78was too small to allow storing the pathname.
a392de7a 79.SH ATTRIBUTES
9768c07d
PH
80For an explanation of the terms used in this section, see
81.BR attributes (7).
82.TS
83allbox;
84lb lb lb
85l l l.
86Interface Attribute Value
87T{
a392de7a 88.BR ttyname ()
fadd3c2b 89T} Thread safety MT-Unsafe race:ttyname
9768c07d 90T{
a392de7a 91.BR ttyname_r ()
9768c07d
PH
92T} Thread safety MT-Safe
93.TE
47297adb 94.SH CONFORMING TO
4fb69fa9 95POSIX.1-2001, POSIX.1-2008, 4.2BSD.
953385d5 96.SH NOTES
02899644 97A process that keeps a file descriptor that refers to a
953385d5 98.BR pts (4)
02899644 99device open when switching to another mount namespace that uses a different
d8a86e74 100.I /dev/ptmx
02899644
MK
101instance may still accidentally find that a device path of the same name
102for that file descriptor exists.
103However, this device path refers to a different device and thus
2c43dda3 104can't be used to access the device that the file descriptor refers to.
02899644 105Calling
2ad31d9d 106.BR ttyname ()
953385d5 107or
2ad31d9d 108.BR ttyname_r ()
02899644
MK
109on the file descriptor in the new mount namespace will cause these
110functions to return NULL and set
111.I errno
112to
113.BR ENODEV .
47297adb 114.SH SEE ALSO
160b2e87 115.BR tty (1),
fea681da 116.BR fstat (2),
cd12460a 117.BR ctermid (3),
1e88383b
DL
118.BR isatty (3),
119.BR pts (4)