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

244 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ERR</TITLE>
</HEAD><BODY>
<H1>ERR</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<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>
err, verr, errx, verrx, warn, vwarn, warnx, vwarnx - formatted error messages
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/err.h">err.h</A>&gt;</B>
<B>void err(int </B><I>eval</I><B>, const char *</B><I>fmt</I><B>, ...);</B>
<B>void errx(int </B><I>eval</I><B>, const char *</B><I>fmt</I><B>, ...);</B>
<B>void warn(const char *</B><I>fmt</I><B>, ...);</B>
<B>void warnx(const char *</B><I>fmt</I><B>, ...);</B>
<B>#include &lt;<A HREF="file:///usr/include/stdarg.h">stdarg.h</A>&gt;</B>
<B>void verr(int </B><I>eval</I><B>, const char *</B><I>fmt</I><B>, va_list </B><I>args</I><B>);</B>
<B>void verrx(int </B><I>eval</I><B>, const char *</B><I>fmt</I><B>, va_list </B><I>args</I><B>);</B>
<B>void vwarn(const char *</B><I>fmt</I><B>, va_list </B><I>args</I><B>);</B>
<B>void vwarnx(const char *</B><I>fmt</I><B>, va_list </B><I>args</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>err</B>()
and
<B>warn</B>()
family of functions display a formatted error message on the standard
error output.
In all cases, the last component of the program name, a colon character,
and a space are output.
If the
<I>fmt</I>
argument is not NULL, the
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3)-like
formatted error message is output.
The output is terminated by a newline character.
<P>
The
<B>err</B>(),
<B>verr</B>(),
<B>warn</B>(),
and
<B>vwarn</B>()
functions append an error message obtained from
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
based on the global variable
<I>errno</I>,
preceded by another colon and space unless the
<I>fmt</I>
argument is
NULL.
<P>
The
<B>errx</B>()
and
<B>warnx</B>()
functions do not append an error message.
<P>
The
<B>err</B>(),
<B>verr</B>(),
<B>errx</B>(),
and
<B>verrx</B>()
functions do not return, but exit with the value of the argument
<I>eval</I>.
<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>err</B>(),
<B>errx</B>(),
<BR>
<B>warn</B>(),
<B>warnx</B>(),
<BR>
<B>verr</B>(),
<B>verrx</B>(),
<BR>
<B>vwarn</B>(),
<B>vwarnx</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAF">&nbsp;</A>
<H2>CONFORMING TO</H2>
These functions are nonstandard BSD extensions.
<A NAME="lbAG">&nbsp;</A>
<H2>EXAMPLE</H2>
Display the current
<I>errno</I>
information string and exit:
<P>
p = malloc(size);
if (p == NULL)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;err(1,&nbsp;NULL);
fd = open(file_name, O_RDONLY, 0);
if (fd == -1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;err(1,&nbsp;&quot;%s&quot;,&nbsp;file_name);
<P>
Display an error message and exit:
<P>
if (tm.tm_hour &lt; START_TIME)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;errx(1,&nbsp;&quot;too&nbsp;early,&nbsp;wait&nbsp;until&nbsp;%s&quot;,&nbsp;start_time_string);
<P>
Warn of an error:
<P>
fd = open(raw_device, O_RDONLY, 0);
if (fd == -1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;warnx(&quot;%s:&nbsp;%s:&nbsp;trying&nbsp;the&nbsp;block&nbsp;device&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw_device,&nbsp;strerror(errno));
fd = open(block_device, O_RDONLY, 0);
if (fd == -1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;err(1,&nbsp;&quot;%s&quot;,&nbsp;block_device);
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+error">error</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</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">EXAMPLE</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:39 GMT, March 31, 2021
</BODY>
</HTML>