1ERROR(3)                   Linux Programmer's Manual                  ERROR(3)
2
3
4

NAME

6       error,   error_at_line,  error_message_count,  error_one_per_line,  er‐
7       ror_print_progname - glibc error reporting functions
8

SYNOPSIS

10       #include <error.h>
11
12       void error(int status, int errnum, const char *format, ...);
13       void error_at_line(int status, int errnum, const char *filename,
14                          unsigned int linenum, const char *format, ...);
15
16       extern unsigned int error_message_count;
17       extern int error_one_per_line;
18
19       extern void (*error_print_progname)(void);
20

DESCRIPTION

22       error() is a general error-reporting function.  It flushes stdout,  and
23       then  outputs to stderr the program name, a colon and a space, the mes‐
24       sage specified by the printf(3)-style format string format, and, if er‐
25       rnum  is  nonzero,  a  second  colon and a space followed by the string
26       given by strerror(errnum).  Any arguments required  for  format  should
27       follow format in the argument list.  The output is terminated by a new‐
28       line character.
29
30       The program name printed by error() is the value of the global variable
31       program_invocation_name(3).   program_invocation_name initially has the
32       same value as main()'s argv[0].  The value of this variable can be mod‐
33       ified to change the output of error().
34
35       If  status has a nonzero value, then error() calls exit(3) to terminate
36       the program using the given value as the exit status; otherwise it  re‐
37       turns after printing the error message.
38
39       The error_at_line() function is exactly the same as error(), except for
40       the addition of the arguments filename and linenum.   The  output  pro‐
41       duced  is  as for error(), except that after the program name are writ‐
42       ten: a colon, the value of filename, a colon, and the value of linenum.
43       The  preprocessor values __LINE__ and __FILE__ may be useful when call‐
44       ing error_at_line(), but other values can also be used.   For  example,
45       these arguments could refer to a location in an input file.
46
47       If the global variable error_one_per_line is set nonzero, a sequence of
48       error_at_line() calls with the same value of filename and linenum  will
49       result in only one message (the first) being output.
50
51       The  global  variable error_message_count counts the number of messages
52       that have been output by error() and error_at_line().
53
54       If the global variable error_print_progname is assigned the address  of
55       a function (i.e., is not NULL), then that function is called instead of
56       prefixing the message with the program name and  colon.   The  function
57       should print a suitable string to stderr.
58

ATTRIBUTES

60       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
61       tributes(7).
62
63       ┌────────────────┬───────────────┬─────────────────────────────────────┐
64Interface       Attribute     Value                               
65       ├────────────────┼───────────────┼─────────────────────────────────────┤
66error()         │ Thread safety │ MT-Safe locale                      │
67       ├────────────────┼───────────────┼─────────────────────────────────────┤
68error_at_line() │ Thread safety │ MT-Unsafe race: error_at_line/      │
69       │                │               │ error_one_per_line locale           │
70       └────────────────┴───────────────┴─────────────────────────────────────┘
71
72       The  internal error_one_per_line variable is accessed (without any form
73       of synchronization, but since it's an int used once, it should be  safe
74       enough)  and, if error_one_per_line is set nonzero, the internal static
75       variables (not exposed to users) used to hold the last printed filename
76       and  line number are accessed and modified without synchronization; the
77       update is not atomic and it occurs before disabling cancellation, so it
78       can  be  interrupted  only  after one of the two variables is modified.
79       After that, error_at_line() is very much like error().
80

CONFORMING TO

82       These functions and variables are GNU extensions,  and  should  not  be
83       used in programs intended to be portable.
84

SEE ALSO

86       err(3),  errno(3), exit(3), perror(3), program_invocation_name(3), str‐
87       error(3)
88

COLOPHON

90       This page is part of release 5.12 of the Linux  man-pages  project.   A
91       description  of  the project, information about reporting bugs, and the
92       latest    version    of    this    page,    can     be     found     at
93       https://www.kernel.org/doc/man-pages/.
94
95
96
97GNU                               2021-03-22                          ERROR(3)
Impressum