|
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | ATTRIBUTES | STANDARDS | SEE ALSO | COLOPHON |
|
|
|
error(3) Library Functions Manual error(3)
error, error_at_line, error_message_count, error_one_per_line,
error_print_progname - glibc error reporting functions
Standard C library (libc, -lc)
#include <error.h>
void error(int status, int errnum, const char *format, ...);
void error_at_line(int status, int errnum, const char *file,
unsigned int line, const char *format, ...);
extern unsigned int error_message_count;
extern int error_one_per_line;
extern typeof(void (void)) *error_print_progname;
error() is a general error-reporting function. It flushes stdout,
and then outputs to stderr the program name, a colon and a space,
the message specified by the printf(3)-style format string format,
and, if errnum is nonzero, a second colon and a space followed by
the string given by strerror(errnum). Any arguments required for
format should follow format in the argument list. The output is
terminated by a newline character.
The program name printed by error() is the value of the global
variable program_invocation_name(3). program_invocation_name
initially has the same value as main()'s argv[0]. The value of
this variable can be modified to change the output of error().
If status has a nonzero value, then error() calls exit(3) to
terminate the program using the given value as the exit status;
otherwise it returns after printing the error message.
The error_at_line() function is exactly the same as error(),
except for the addition of the arguments file and line. The
output produced is as for error(), except that after the program
name are written: a colon, the value of file, a colon, and the
value of line. The preprocessor values __LINE__ and __FILE__ may
be useful when calling error_at_line(), but other values can also
be used. For example, these arguments could refer to a location
in an input file.
If the global variable error_one_per_line is set nonzero, a
sequence of error_at_line() calls with the same value of file and
line will result in only one message (the first) being output.
The global variable error_message_count counts the number of
messages that have been output by error() and error_at_line().
If the global variable error_print_progname 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 stderr.
For an explanation of the terms used in this section, see
attributes(7).
┌─────────────────┬───────────────┬──────────────────────────────┐
│ Interface │ Attribute │ Value │
├─────────────────┼───────────────┼──────────────────────────────┤
│ error() │ Thread safety │ MT-Safe locale │
├─────────────────┼───────────────┼──────────────────────────────┤
│ error_at_line() │ Thread safety │ MT-Unsafe race: │
│ │ │ error_at_line/ │
│ │ │ error_one_per_line locale │
└─────────────────┴───────────────┴──────────────────────────────┘
The internal error_one_per_line variable is accessed (without any
form of synchronization, but since it's an int used once, it
should be safe enough) and, if error_one_per_line 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 cancelation, so it can be interrupted only
after one of the two variables is modified. After that,
error_at_line() is very much like error().
GNU.
err(3), errno(3), exit(3), perror(3), program_invocation_name(3),
strerror(3)
This page is part of the man-pages (Linux kernel and C library
user-space interface documentation) project. Information about
the project can be found at
⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report
for this manual page, see
⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
This page was obtained from the tarball man-pages-6.15.tar.gz
fetched from
⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
2025-08-11. If you discover any rendering problems in this HTML
version of the page, or you believe there is a better or more up-
to-date source for the page, or you have corrections or
improvements to the information in this COLOPHON (which is not
part of the original manual page), send a mail to
[email protected]
Linux man-pages 6.15 2025-06-05 error(3)
Pages that refer to this page: err(3), errno(3), perror(3), strerror(3), sysexits.h(3head)
Copyright and license for this manual page