Blame man3/error.3

Packit 7cfc04
.\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
Packit 7cfc04
.\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(PERMISSIVE_MISC)
Packit 7cfc04
.\" Permission is hereby granted, free of charge, to any person obtaining
Packit 7cfc04
.\" a copy of this software and associated documentation files (the
Packit 7cfc04
.\" "Software"), to deal in the Software without restriction, including
Packit 7cfc04
.\" without limitation the rights to use, copy, modify, merge, publish,
Packit 7cfc04
.\" distribute, sublicense, and/or sell copies of the Software, and to
Packit 7cfc04
.\" permit persons to whom the Software is furnished to do so, subject to
Packit 7cfc04
.\" the following conditions:
Packit 7cfc04
.\"
Packit 7cfc04
.\" The above copyright notice and this permission notice shall be
Packit 7cfc04
.\" included in all copies or substantial portions of the Software.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 7cfc04
.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 7cfc04
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit 7cfc04
.\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Packit 7cfc04
.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Packit 7cfc04
.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Packit 7cfc04
.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" References:
Packit 7cfc04
.\"   glibc manual and source
Packit 7cfc04
.TH ERROR 3 2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
error, error_at_line, error_message_count, error_one_per_line,
Packit 7cfc04
error_print_progname \- glibc error reporting functions
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <error.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void error(int " status ", int " errnum ", const char *" format ", ...);"
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void error_at_line(int " status ", int " errnum ", const char *" filename ,
Packit 7cfc04
.BI "                   unsigned int " linenum ", const char *" format ", ...);"
Packit 7cfc04
.PP
Packit 7cfc04
.BI "extern unsigned int " error_message_count ;
Packit 7cfc04
.PP
Packit 7cfc04
.BI "extern int " error_one_per_line ;
Packit 7cfc04
.PP
Packit 7cfc04
.BI "extern void (*" error_print_progname ") (void);"
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR error ()
Packit 7cfc04
is a general error-reporting function.
Packit 7cfc04
It flushes
Packit 7cfc04
.IR stdout ,
Packit 7cfc04
and then outputs to
Packit 7cfc04
.I stderr
Packit 7cfc04
the program name, a colon and a space, the message specified by the
Packit 7cfc04
.BR printf (3)-style
Packit 7cfc04
format string \fIformat\fP, and, if \fIerrnum\fP is
Packit 7cfc04
nonzero, a second colon and a space followed by the string given by
Packit 7cfc04
.IR strerror(errnum) .
Packit 7cfc04
Any arguments required for
Packit 7cfc04
.I format
Packit 7cfc04
should follow
Packit 7cfc04
.I format
Packit 7cfc04
in the argument list.
Packit 7cfc04
The output is terminated by a newline character.
Packit 7cfc04
.PP
Packit 7cfc04
The program name printed by
Packit 7cfc04
.BR error ()
Packit 7cfc04
is the value of the global variable
Packit 7cfc04
.BR program_invocation_name (3).
Packit 7cfc04
.I program_invocation_name
Packit 7cfc04
initially has the same value as
Packit 7cfc04
.IR main ()'s
Packit 7cfc04
.IR argv[0] .
Packit 7cfc04
The value of this variable can be modified to change the output of
Packit 7cfc04
.BR error ().
Packit 7cfc04
.PP
Packit 7cfc04
If \fIstatus\fP has a nonzero value, then
Packit 7cfc04
.BR error ()
Packit 7cfc04
calls
Packit 7cfc04
.BR exit (3)
Packit 7cfc04
to terminate the program using the given value as the exit status.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR error_at_line ()
Packit 7cfc04
function is exactly the same as
Packit 7cfc04
.BR error (),
Packit 7cfc04
except for the addition of the arguments
Packit 7cfc04
.I filename
Packit 7cfc04
and
Packit 7cfc04
.IR linenum .
Packit 7cfc04
The output produced is as for
Packit 7cfc04
.BR error (),
Packit 7cfc04
except that after the program name are written: a colon, the value of
Packit 7cfc04
.IR filename ,
Packit 7cfc04
a colon, and the value of
Packit 7cfc04
.IR linenum .
Packit 7cfc04
The preprocessor values \fB__LINE__\fP and
Packit 7cfc04
\fB__FILE__\fP may be useful when calling
Packit 7cfc04
.BR error_at_line (),
Packit 7cfc04
but other values can also be used.
Packit 7cfc04
For example, these arguments could refer to a location in an input file.
Packit 7cfc04
.PP
Packit 7cfc04
If the global variable \fIerror_one_per_line\fP is set nonzero,
Packit 7cfc04
a sequence of
Packit 7cfc04
.BR error_at_line ()
Packit 7cfc04
calls with the
Packit 7cfc04
same value of \fIfilename\fP and \fIlinenum\fP will result in only
Packit 7cfc04
one message (the first) being output.
Packit 7cfc04
.PP
Packit 7cfc04
The global variable \fIerror_message_count\fP counts the number of
Packit 7cfc04
messages that have been output by
Packit 7cfc04
.BR error ()
Packit 7cfc04
and
Packit 7cfc04
.BR error_at_line ().
Packit 7cfc04
.PP
Packit 7cfc04
If the global variable \fIerror_print_progname\fP
Packit 7cfc04
is assigned the address of a function
Packit 7cfc04
(i.e., is not NULL), then that function is called
Packit 7cfc04
instead of prefixing the message with the program name and colon.
Packit 7cfc04
The function should print a suitable string to
Packit 7cfc04
.IR stderr .
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.ad l
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lb lb lbw33
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR error ()
Packit 7cfc04
T}	Thread safety	MT-Safe locale
Packit 7cfc04
T{
Packit 7cfc04
.BR error_at_line ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe\ race: error_at_line/error_one_per_line locale
Packit 7cfc04
T}
Packit 7cfc04
.TE
Packit 7cfc04
.ad
Packit 7cfc04
.PP
Packit 7cfc04
The internal
Packit 7cfc04
.I error_one_per_line
Packit 7cfc04
variable is accessed (without any form of synchronization, but since it's an
Packit 7cfc04
.I int
Packit 7cfc04
used once, it should be safe enough) and, if
Packit 7cfc04
.I error_one_per_line
Packit 7cfc04
is set nonzero, the internal static variables (not exposed to users)
Packit 7cfc04
used to hold the last printed filename and line number are accessed
Packit 7cfc04
and modified without synchronization; the update is not atomic and it
Packit 7cfc04
occurs before disabling cancellation, so it can be interrupted only after
Packit 7cfc04
one of the two variables is modified.
Packit 7cfc04
After that,
Packit 7cfc04
.BR error_at_line ()
Packit 7cfc04
is very much like
Packit 7cfc04
.BR error ().
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
These functions and variables are GNU extensions, and should not be
Packit 7cfc04
used in programs intended to be portable.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR err (3),
Packit 7cfc04
.BR errno (3),
Packit 7cfc04
.BR exit (3),
Packit 7cfc04
.BR perror (3),
Packit 7cfc04
.BR program_invocation_name (3),
Packit 7cfc04
.BR strerror (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.