238 lines
5.9 KiB
HTML
238 lines
5.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of ERROR</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>ERROR</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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
error, error_at_line, error_message_count, error_one_per_line,
|
|
error_print_progname - glibc error reporting functions
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/error.h">error.h</A>></B>
|
|
|
|
<B>void error(int </B><I>status</I><B>, int </B><I>errnum</I><B>, const char *</B><I>format</I><B>, ...);</B>
|
|
|
|
<B>void error_at_line(int </B><I>status</I><B>, int </B><I>errnum</I><B>, const char *</B><I>filename</I><B>,</B>
|
|
<B> unsigned int </B><I>linenum</I><B>, const char *</B><I>format</I><B>, ...);</B>
|
|
|
|
<B>extern unsigned int </B><I>error_message_count</I><B>;</B>
|
|
|
|
<B>extern int </B><I>error_one_per_line</I><B>;</B>
|
|
|
|
<B>extern void (*</B><I>error_print_progname</I><B>) (void);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>error</B>()
|
|
|
|
is a general error-reporting function.
|
|
It flushes
|
|
<I>stdout</I>,
|
|
|
|
and then outputs to
|
|
<I>stderr</I>
|
|
|
|
the program name, a colon and a space, the message specified by the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3)-style
|
|
|
|
format string <I>format</I>, and, if <I>errnum</I> is
|
|
nonzero, a second colon and a space followed by the string given by
|
|
<I>strerror(errnum)</I>.
|
|
|
|
Any arguments required for
|
|
<I>format</I>
|
|
|
|
should follow
|
|
<I>format</I>
|
|
|
|
in the argument list.
|
|
The output is terminated by a newline character.
|
|
<P>
|
|
|
|
The program name printed by
|
|
<B>error</B>()
|
|
|
|
is the value of the global variable
|
|
<B><A HREF="/cgi-bin/man/man2html?3+program_invocation_name">program_invocation_name</A></B>(3).
|
|
|
|
<I>program_invocation_name</I>
|
|
|
|
initially has the same value as
|
|
<I>main</I>()'s
|
|
|
|
<I>argv[0]</I>.
|
|
|
|
The value of this variable can be modified to change the output of
|
|
<B>error</B>().
|
|
|
|
<P>
|
|
|
|
If <I>status</I> has a nonzero value, then
|
|
<B>error</B>()
|
|
|
|
calls
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3)
|
|
|
|
to terminate the program using the given value as the exit status.
|
|
<P>
|
|
|
|
The
|
|
<B>error_at_line</B>()
|
|
|
|
function is exactly the same as
|
|
<B>error</B>(),
|
|
|
|
except for the addition of the arguments
|
|
<I>filename</I>
|
|
|
|
and
|
|
<I>linenum</I>.
|
|
|
|
The output produced is as for
|
|
<B>error</B>(),
|
|
|
|
except that after the program name are written: a colon, the value of
|
|
<I>filename</I>,
|
|
|
|
a colon, and the value of
|
|
<I>linenum</I>.
|
|
|
|
The preprocessor values <B>__LINE__</B> and
|
|
<B>__FILE__</B> may be useful when calling
|
|
<B>error_at_line</B>(),
|
|
|
|
but other values can also be used.
|
|
For example, these arguments could refer to a location in an input file.
|
|
<P>
|
|
|
|
If the global variable <I>error_one_per_line</I> is set nonzero,
|
|
a sequence of
|
|
<B>error_at_line</B>()
|
|
|
|
calls with the
|
|
same value of <I>filename</I> and <I>linenum</I> will result in only
|
|
one message (the first) being output.
|
|
<P>
|
|
|
|
The global variable <I>error_message_count</I> counts the number of
|
|
messages that have been output by
|
|
<B>error</B>()
|
|
|
|
and
|
|
<B>error_at_line</B>().
|
|
|
|
<P>
|
|
|
|
If the global variable <I>error_print_progname</I>
|
|
is assigned the address of a function
|
|
(i.e., is not NULL), then that function is called
|
|
instead of prefixing the message with the program name and colon.
|
|
The function should print a suitable string to
|
|
<I>stderr</I>.
|
|
|
|
<A NAME="lbAE"> </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>error</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>error_at_line</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race: error_at_line/error_one_per_line locale
|
|
<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
|
|
<P>
|
|
|
|
The internal
|
|
<I>error_one_per_line</I>
|
|
|
|
variable is accessed (without any form of synchronization, but since it's an
|
|
<I>int</I>
|
|
|
|
used once, it should be safe enough) and, if
|
|
<I>error_one_per_line</I>
|
|
|
|
is set nonzero, the internal static variables (not exposed to users)
|
|
used to hold the last printed filename and line number are accessed
|
|
and modified without synchronization; the update is not atomic and it
|
|
occurs before disabling cancellation, so it can be interrupted only after
|
|
one of the two variables is modified.
|
|
After that,
|
|
<B>error_at_line</B>()
|
|
|
|
is very much like
|
|
<B>error</B>().
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These functions and variables are GNU extensions, and should not be
|
|
used in programs intended to be portable.
|
|
<A NAME="lbAG"> </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+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+program_invocation_name">program_invocation_name</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
|
|
|
|
<A NAME="lbAH"> </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"> </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">SEE ALSO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">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>
|