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

229 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PERROR</TITLE>
</HEAD><BODY>
<H1>PERROR</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<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>
perror - print a system error message
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;</B>
<P>
<B>void perror(const char *</B><I>s</I><B>);</B>
<P>
<B>#include &lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</B>
<P>
<B>const char * const </B><I>sys_errlist</I><B>[];</B>
<BR>
<B>int </B><I>sys_nerr</I><B>;</B>
<BR>
<B>int </B><I>errno</I><B>; </B>/* Not really declared this way; see <A HREF="/cgi-bin/man/man2html?3+errno">errno</A>(3) */
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<I>sys_errlist</I>,
<I>sys_nerr</I>:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_BSD_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>perror</B>()
function produces a message on standard error describing the last
error encountered during a call to a system or library function.
<P>
First (if
<I>s</I>
is not NULL and
<I>*s</I>
is not a null byte ('\0')), the argument string
<I>s</I>
is printed, followed by a colon and a blank.
Then an error message corresponding to the current value of
<I>errno</I>
and a new-line.
<P>
To be of most use, the argument string should include the name
of the function that incurred the error.
<P>
The global error list
<I>sys_errlist</I>[],
which can be indexed by
<I>errno</I>,
can be used to obtain the error message without the newline.
The largest message number provided in the table is
<I>sys_nerr</I>-1.
Be careful when directly accessing this list, because new error values
may not have been added to
<I>sys_errlist</I>[].
The use of
<I>sys_errlist</I>[]
is nowadays deprecated; use
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
instead.
<P>
When a system call fails, it usually returns -1 and sets the
variable
<I>errno</I>
to a value describing what went wrong.
(These values can be found in
<I>&lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</I>.)
Many library functions do likewise.
The function
<B>perror</B>()
serves to translate this error code into human-readable form.
Note that
<I>errno</I>
is undefined after a successful system call or library function call:
this call may well change this variable, even though it succeeds,
for example because it internally used some other library function that failed.
Thus, if a failing call is not immediately followed by a call to
<B>perror</B>(),
the value of
<I>errno</I>
should be saved.
<A NAME="lbAE">&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>perror</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe race:stderr<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAF">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>perror</B>(),
<I>errno</I>:
POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.
<P>
The externals
<I>sys_nerr</I>
and
<I>sys_errlist</I>
derive from BSD, but are not specified in POSIX.1.
<A NAME="lbAG">&nbsp;</A>
<H2>NOTES</H2>
The externals
<I>sys_nerr</I>
and
<I>sys_errlist</I>
are defined by glibc, but in
<I>&lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;</I>.
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+err">err</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+errno">errno</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+error">error</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
<A NAME="lbAI">&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="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">ATTRIBUTES</A><DD>
<DT id="5"><A HREF="#lbAF">CONFORMING TO</A><DD>
<DT id="6"><A HREF="#lbAG">NOTES</A><DD>
<DT id="7"><A HREF="#lbAH">SEE ALSO</A><DD>
<DT id="8"><A HREF="#lbAI">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:52 GMT, March 31, 2021
</BODY>
</HTML>