]>
Commit | Line | Data |
---|---|---|
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 |
10 | ttyname, ttyname_r \- return name of a terminal | |
e72ce02f AC |
11 | .SH LIBRARY |
12 | Standard 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 | |
22 | The function | |
23 | .BR ttyname () | |
28d88c17 | 24 | returns a pointer to the null-terminated pathname of the terminal device |
35e21ba7 | 25 | that 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). |
27 | The return value may point to static data, possibly overwritten by the | |
28 | next call. | |
29 | The function | |
30 | .BR ttyname_r () | |
31 | stores this pathname in the buffer | |
32 | .I buf | |
33 | of length | |
34 | .IR buflen . | |
47297adb | 35 | .SH RETURN VALUE |
fea681da MK |
36 | The function |
37 | .BR ttyname () | |
c13182ef | 38 | returns a pointer to a pathname on success. |
8478ee02 | 39 | On error, NULL is returned, and |
fea681da | 40 | .I errno |
f6a4078b | 41 | is set to indicate the error. |
fea681da MK |
42 | The function |
43 | .BR ttyname_r () | |
44 | returns 0 on success, and an error number upon error. | |
45 | .SH ERRORS | |
fea681da MK |
46 | .TP |
47 | .B EBADF | |
48 | Bad file descriptor. | |
49 | .TP | |
49a2a105 MK |
50 | .\" glibc commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 |
51 | .B ENODEV | |
e87eb066 MK |
52 | .I fd |
53 | refers to a slave pseudoterminal device | |
49a2a105 MK |
54 | but the corresponding pathname could not be found (see NOTES). |
55 | .TP | |
fea681da | 56 | .B ENOTTY |
e87eb066 MK |
57 | .I fd |
58 | does not refer to a terminal device. | |
fea681da MK |
59 | .TP |
60 | .B ERANGE | |
4bcf0534 | 61 | .RB ( ttyname_r ()) |
fea681da MK |
62 | .I buflen |
63 | was too small to allow storing the pathname. | |
a392de7a | 64 | .SH ATTRIBUTES |
9768c07d PH |
65 | For 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 |
70 | allbox; | |
c466875e | 71 | lbx lb lb |
9768c07d PH |
72 | l l l. |
73 | Interface Attribute Value | |
74 | T{ | |
a392de7a | 75 | .BR ttyname () |
fadd3c2b | 76 | T} Thread safety MT-Unsafe race:ttyname |
9768c07d | 77 | T{ |
a392de7a | 78 | .BR ttyname_r () |
9768c07d PH |
79 | T} Thread safety MT-Safe |
80 | .TE | |
c466875e MK |
81 | .hy |
82 | .ad | |
83 | .sp 1 | |
3113c7f3 | 84 | .SH STANDARDS |
4fb69fa9 | 85 | POSIX.1-2001, POSIX.1-2008, 4.2BSD. |
953385d5 | 86 | .SH NOTES |
02899644 | 87 | A process that keeps a file descriptor that refers to a |
953385d5 | 88 | .BR pts (4) |
02899644 | 89 | device open when switching to another mount namespace that uses a different |
d8a86e74 | 90 | .I /dev/ptmx |
02899644 MK |
91 | instance may still accidentally find that a device path of the same name |
92 | for that file descriptor exists. | |
93 | However, this device path refers to a different device and thus | |
2c43dda3 | 94 | can't be used to access the device that the file descriptor refers to. |
02899644 | 95 | Calling |
2ad31d9d | 96 | .BR ttyname () |
953385d5 | 97 | or |
2ad31d9d | 98 | .BR ttyname_r () |
02899644 MK |
99 | on the file descriptor in the new mount namespace will cause these |
100 | functions to return NULL and set | |
101 | .I errno | |
102 | to | |
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) |