OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / ttyname.3
1 .\" Copyright (c) 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
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
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\" Modified 2001-12-13, Martin Schulze <joey@infodrom.org>
25 .\" Added ttyname_r, aeb, 2002-07-20
26 .\"
27 .TH TTYNAME 3 2013-06-21 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 ttyname, ttyname_r \- return name of a terminal
30 .SH SYNOPSIS
31 .nf
32 .B #include <unistd.h>
33 .sp
34 .BI "char *ttyname(int " fd );
35
36 .BI "int ttyname_r(int " fd ", char *" buf ", size_t " buflen );
37 .fi
38 .SH DESCRIPTION
39 The function
40 .BR ttyname ()
41 returns a pointer to the null-terminated pathname of the terminal device
42 that is open on the file descriptor \fIfd\fP, or NULL on error
43 (for example, if \fIfd\fP is not connected to a terminal).
44 The return value may point to static data, possibly overwritten by the
45 next call.
46 The function
47 .BR ttyname_r ()
48 stores this pathname in the buffer
49 .I buf
50 of length
51 .IR buflen .
52 .SH RETURN VALUE
53 The function
54 .BR ttyname ()
55 returns a pointer to a pathname on success.
56 On error, NULL is returned, and
57 .I errno
58 is set appropriately.
59 The function
60 .BR ttyname_r ()
61 returns 0 on success, and an error number upon error.
62 .SH ERRORS
63 .TP
64 .B EBADF
65 Bad file descriptor.
66 .TP
67 .B ENOTTY
68 File descriptor does not refer to a terminal device.
69 .TP
70 .B ERANGE
71 .RB ( ttyname_r ())
72 .I buflen
73 was too small to allow storing the pathname.
74 .SH ATTRIBUTES
75 .SS Multithreading (see pthreads(7))
76 The
77 .BR ttyname ()
78 function is not thread-safe.
79 .LP
80 The
81 .BR ttyname_r ()
82 function is thread-safe.
83 .SH CONFORMING TO
84 4.2BSD, POSIX.1-2001.
85 .SH SEE ALSO
86 .BR fstat (2),
87 .BR ctermid (3),
88 .BR isatty (3)
89 .SH COLOPHON
90 This page is part of release 3.68 of the Linux
91 .I man-pages
92 project.
93 A description of the project,
94 information about reporting bugs,
95 and the latest version of this page,
96 can be found at
97 \%http://www.kernel.org/doc/man\-pages/.