]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/ttyname.3
Merge llvm-project release/17.x llvmorg-17.0.3-0-g888437e1b600
[FreeBSD/FreeBSD.git] / lib / libc / gen / ttyname.3
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .Dd July 18, 2014
29 .Dt TTYNAME 3
30 .Os
31 .Sh NAME
32 .Nm ttyname ,
33 .Nm ttyname_r ,
34 .Nm isatty
35 .Nd get name of associated terminal (tty) from file descriptor
36 .Sh LIBRARY
37 .Lb libc
38 .Sh SYNOPSIS
39 .In unistd.h
40 .Ft char *
41 .Fn ttyname "int fd"
42 .Ft int
43 .Fn ttyname_r "int fd" "char *buf" "size_t len"
44 .Ft int
45 .Fn isatty "int fd"
46 .Sh DESCRIPTION
47 These functions operate on file descriptors for terminal type devices.
48 .Pp
49 The
50 .Fn isatty
51 function
52 determines if the file descriptor
53 .Fa fd
54 refers to a valid
55 terminal type device.
56 .Pp
57 The
58 .Fn ttyname
59 function
60 gets the related device name of
61 a file descriptor for which
62 .Fn isatty
63 is true.
64 .Pp
65 The
66 .Fn ttyname
67 function
68 returns the name stored in a static buffer which will be overwritten
69 on subsequent calls.
70 The
71 .Fn ttyname_r
72 function
73 takes a buffer and length as arguments to avoid this problem.
74 .Sh RETURN VALUES
75 The
76 .Fn isatty
77 function returns 1 if
78 .Fa fd
79 refers to a terminal type device;
80 otherwise, it returns 0 and may set
81 .Va errno
82 to indicate the error.
83 The
84 .Fn ttyname
85 function
86 returns the null terminated name if the device is found and
87 .Fn isatty
88 is true; otherwise
89 a
90 .Dv NULL
91 pointer is returned.
92 The
93 .Fn ttyname_r
94 function returns 0 if successful.
95 Otherwise an error number is returned.
96 .Sh ERRORS
97 These functions may fail if:
98 .Bl -tag -width Er
99 .It Bq Er EBADF
100 The
101 .Fa fd
102 argument
103 is not a valid file descriptor.
104 .It Bq Er ENOTTY
105 The file associated with
106 .Fa fd
107 is not a terminal.
108 .El
109 .Pp
110 Additionally,
111 .Fn ttyname_r
112 may fail if:
113 .Bl -tag -width Er
114 .It Bq Er ERANGE
115 The
116 .Fa bufsize
117 argument
118 is smaller than the length of the string to be returned.
119 .El
120 .Sh SEE ALSO
121 .Xr fdevname 3 ,
122 .Xr ptsname 3 ,
123 .Xr tcgetattr 3 ,
124 .Xr tty 4
125 .Sh HISTORY
126 The
127 .Fn isatty
128 and
129 .Fn ttyname
130 functions
131 appeared in
132 .At v7 .
133 The
134 .Fn ttyname_r
135 function
136 appeared in
137 .Fx 6.0 .