]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/ttyname.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / ttyname.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
c13182ef 4.\"
fea681da
MK
5.\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
6.\" Added ttyname_r, aeb, 2002-07-20
7.\"
45186a5d 8.TH TTYNAME 3 2021-03-22 "Linux man-pages (unreleased)"
fea681da
MK
9.SH NAME
10ttyname, ttyname_r \- return name of a terminal
e72ce02f
AC
11.SH LIBRARY
12Standard C library
8fc3b2cf 13.RI ( libc ", " \-lc )
fea681da
MK
14.SH SYNOPSIS
15.nf
16.B #include <unistd.h>
68e4db0a 17.PP
fea681da 18.BI "char *ttyname(int " fd );
fea681da
MK
19.BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
20.fi
21.SH DESCRIPTION
22The function
23.BR ttyname ()
28d88c17 24returns a pointer to the null-terminated pathname of the terminal device
35e21ba7 25that is open on the file descriptor \fIfd\fP, or NULL on error
fea681da
MK
26(for example, if \fIfd\fP is not connected to a terminal).
27The return value may point to static data, possibly overwritten by the
28next call.
29The function
30.BR ttyname_r ()
31stores this pathname in the buffer
32.I buf
33of length
34.IR buflen .
47297adb 35.SH RETURN VALUE
fea681da
MK
36The function
37.BR ttyname ()
c13182ef 38returns a pointer to a pathname on success.
8478ee02 39On error, NULL is returned, and
fea681da 40.I errno
f6a4078b 41is set to indicate the error.
fea681da
MK
42The function
43.BR ttyname_r ()
44returns 0 on success, and an error number upon error.
45.SH ERRORS
fea681da
MK
46.TP
47.B EBADF
48Bad file descriptor.
49.TP
49a2a105
MK
50.\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
51.B ENODEV
e87eb066
MK
52.I fd
53refers to a slave pseudoterminal device
49a2a105
MK
54but the corresponding pathname could not be found (see NOTES).
55.TP
fea681da 56.B ENOTTY
e87eb066
MK
57.I fd
58does not refer to a terminal device.
fea681da
MK
59.TP
60.B ERANGE
4bcf0534 61.RB ( ttyname_r ())
fea681da
MK
62.I buflen
63was too small to allow storing the pathname.
a392de7a 64.SH ATTRIBUTES
9768c07d
PH
65For an explanation of the terms used in this section, see
66.BR attributes (7).
c466875e
MK
67.ad l
68.nh
9768c07d
PH
69.TS
70allbox;
c466875e 71lbx lb lb
9768c07d
PH
72l l l.
73Interface Attribute Value
74T{
a392de7a 75.BR ttyname ()
fadd3c2b 76T} Thread safety MT-Unsafe race:ttyname
9768c07d 77T{
a392de7a 78.BR ttyname_r ()
9768c07d
PH
79T} Thread safety MT-Safe
80.TE
c466875e
MK
81.hy
82.ad
83.sp 1
3113c7f3 84.SH STANDARDS
4fb69fa9 85POSIX.1-2001, POSIX.1-2008, 4.2BSD.
953385d5 86.SH NOTES
02899644 87A process that keeps a file descriptor that refers to a
953385d5 88.BR pts (4)
02899644 89device open when switching to another mount namespace that uses a different
d8a86e74 90.I /dev/ptmx
02899644
MK
91instance may still accidentally find that a device path of the same name
92for that file descriptor exists.
93However, this device path refers to a different device and thus
2c43dda3 94can't be used to access the device that the file descriptor refers to.
02899644 95Calling
2ad31d9d 96.BR ttyname ()
953385d5 97or
2ad31d9d 98.BR ttyname_r ()
02899644
MK
99on the file descriptor in the new mount namespace will cause these
100functions to return NULL and set
101.I errno
102to
103.BR ENODEV .
47297adb 104.SH SEE ALSO
160b2e87 105.BR tty (1),
fea681da 106.BR fstat (2),
cd12460a 107.BR ctermid (3),
1e88383b
DL
108.BR isatty (3),
109.BR pts (4)