]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/ttyname.3
bsddialog: import version 1.0
[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 .\"     @(#)ttyname.3   8.1 (Berkeley) 6/4/93
29 .\"
30 .Dd July 18, 2014
31 .Dt TTYNAME 3
32 .Os
33 .Sh NAME
34 .Nm ttyname ,
35 .Nm ttyname_r ,
36 .Nm isatty
37 .Nd get name of associated terminal (tty) from file descriptor
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In unistd.h
42 .Ft char *
43 .Fn ttyname "int fd"
44 .Ft int
45 .Fn ttyname_r "int fd" "char *buf" "size_t len"
46 .Ft int
47 .Fn isatty "int fd"
48 .Sh DESCRIPTION
49 These functions operate on file descriptors for terminal type devices.
50 .Pp
51 The
52 .Fn isatty
53 function
54 determines if the file descriptor
55 .Fa fd
56 refers to a valid
57 terminal type device.
58 .Pp
59 The
60 .Fn ttyname
61 function
62 gets the related device name of
63 a file descriptor for which
64 .Fn isatty
65 is true.
66 .Pp
67 The
68 .Fn ttyname
69 function
70 returns the name stored in a static buffer which will be overwritten
71 on subsequent calls.
72 The
73 .Fn ttyname_r
74 function
75 takes a buffer and length as arguments to avoid this problem.
76 .Sh RETURN VALUES
77 The
78 .Fn isatty
79 function returns 1 if
80 .Fa fd
81 refers to a terminal type device;
82 otherwise, it returns 0 and may set
83 .Va errno
84 to indicate the error.
85 The
86 .Fn ttyname
87 function
88 returns the null terminated name if the device is found and
89 .Fn isatty
90 is true; otherwise
91 a
92 .Dv NULL
93 pointer is returned.
94 The
95 .Fn ttyname_r
96 function returns 0 if successful.
97 Otherwise an error number is returned.
98 .Sh ERRORS
99 These functions may fail if:
100 .Bl -tag -width Er
101 .It Bq Er EBADF
102 The
103 .Fa fd
104 argument
105 is not a valid file descriptor.
106 .It Bq Er ENOTTY
107 The file associated with
108 .Fa fd
109 is not a terminal.
110 .El
111 .Pp
112 Additionally,
113 .Fn ttyname_r
114 may fail if:
115 .Bl -tag -width Er
116 .It Bq Er ERANGE
117 The
118 .Fa bufsize
119 argument
120 is smaller than the length of the string to be returned.
121 .El
122 .Sh SEE ALSO
123 .Xr fdevname 3 ,
124 .Xr ptsname 3 ,
125 .Xr tcgetattr 3 ,
126 .Xr tty 4
127 .Sh HISTORY
128 The
129 .Fn isatty
130 and
131 .Fn ttyname
132 functions
133 appeared in
134 .At v7 .
135 The
136 .Fn ttyname_r
137 function
138 appeared in
139 .Fx 6.0 .