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
14       void error_at_line(int status, int errnum, const char *filename,
15                          unsigned int linenum, const char *format, ...);
16
17       extern unsigned int error_message_count;
18
19       extern int error_one_per_line;
20
21       extern void (*error_print_progname) (void);
22

DESCRIPTION

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

ATTRIBUTES

61       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
62       tributes(7).
63
64       ┌────────────────┬───────────────┬───────────────────────────────────┐
65Interface       Attribute     Value                             
66       ├────────────────┼───────────────┼───────────────────────────────────┤
67error()         │ Thread safety │ MT-Safe locale                    │
68       ├────────────────┼───────────────┼───────────────────────────────────┤
69error_at_line() │ Thread safety │ MT-Unsafe race: error_at_line/er‐ │
70       │                │               │ ror_one_per_line locale           │
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.10 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                               2017-09-15                          ERROR(3)
Impressum