man-pages/man3/ttyname.3.html
2021-03-31 01:06:50 +01:00

182 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of TTYNAME</TITLE>
</HEAD><BODY>
<H1>TTYNAME</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-10-10<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
ttyname, ttyname_r - return name of a terminal
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<B>char *ttyname(int </B><I>fd</I><B>);</B>
<B>int ttyname_r(int </B><I>fd</I><B>, char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The function
<B>ttyname</B>()
returns a pointer to the null-terminated pathname of the terminal device
that is open on the file descriptor <I>fd</I>, or NULL on error
(for example, if <I>fd</I> is not connected to a terminal).
The return value may point to static data, possibly overwritten by the
next call.
The function
<B>ttyname_r</B>()
stores this pathname in the buffer
<I>buf</I>
of length
<I>buflen</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The function
<B>ttyname</B>()
returns a pointer to a pathname on success.
On error, NULL is returned, and
<I>errno</I>
is set appropriately.
The function
<B>ttyname_r</B>()
returns 0 on success, and an error number upon error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EBADF</B>
<DD>
Bad file descriptor.
<DT id="2">
<DD>
<B>ENODEV</B>
File descriptor refers to a slave pseudoterminal device
but the corresponding pathname could not be found (see NOTES).
<DT id="3"><B>ENOTTY</B>
<DD>
File descriptor does not refer to a terminal device.
<DT id="4"><B>ERANGE</B>
<DD>
(<B>ttyname_r</B>())
<I>buflen</I>
was too small to allow storing the pathname.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>ttyname</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:ttyname<BR></TD></TR>
<TR VALIGN=top><TD>
<B>ttyname_r</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, 4.2BSD.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
A process that keeps a file descriptor that refers to a
<B><A HREF="/cgi-bin/man/man2html?4+pts">pts</A></B>(4)
device open when switching to another mount namespace that uses a different
<I>/dev/ptmx</I>
instance may still accidentally find that a device path of the same name
for that file descriptor exists.
However, this device path refers to a different device and thus
can't be used to access the device that the file descriptor refers to.
Calling
<B>ttyname</B>()
or
<B>ttyname_r</B>()
on the file descriptor in the new mount namespace will cause these
functions to return NULL and set
<I>errno</I>
to
<B>ENODEV</B>.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+tty">tty</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+fstat">fstat</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+ctermid">ctermid</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+isatty">isatty</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?4+pts">pts</A></B>(4)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="9"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="10"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="11"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="12"><A HREF="#lbAI">NOTES</A><DD>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:58 GMT, March 31, 2021
</BODY>
</HTML>