1error(3) Library Functions Manual error(3)
2
3
4
6 error, error_at_line, error_message_count, error_one_per_line, er‐
7 ror_print_progname - glibc error reporting functions
8
10 Standard C library (libc, -lc)
11
13 #include <error.h>
14
15 void error(int status, int errnum, const char *format, ...);
16 void error_at_line(int status, int errnum, const char *filename,
17 unsigned int linenum, const char *format, ...);
18
19 extern unsigned int error_message_count;
20 extern int error_one_per_line;
21
22 extern void (*error_print_progname)(void);
23
25 error() is a general error-reporting function. It flushes stdout, and
26 then outputs to stderr the program name, a colon and a space, the mes‐
27 sage specified by the printf(3)-style format string format, and, if er‐
28 rnum is nonzero, a second colon and a space followed by the string
29 given by strerror(errnum). Any arguments required for format should
30 follow format in the argument list. The output is terminated by a new‐
31 line character.
32
33 The program name printed by error() is the value of the global variable
34 program_invocation_name(3). program_invocation_name initially has the
35 same value as main()'s argv[0]. The value of this variable can be mod‐
36 ified to change the output of error().
37
38 If status has a nonzero value, then error() calls exit(3) to terminate
39 the program using the given value as the exit status; otherwise it re‐
40 turns after printing the error message.
41
42 The error_at_line() function is exactly the same as error(), except for
43 the addition of the arguments filename and linenum. The output pro‐
44 duced is as for error(), except that after the program name are writ‐
45 ten: a colon, the value of filename, a colon, and the value of linenum.
46 The preprocessor values __LINE__ and __FILE__ may be useful when call‐
47 ing error_at_line(), but other values can also be used. For example,
48 these arguments could refer to a location in an input file.
49
50 If the global variable error_one_per_line is set nonzero, a sequence of
51 error_at_line() calls with the same value of filename and linenum will
52 result in only one message (the first) being output.
53
54 The global variable error_message_count counts the number of messages
55 that have been output by error() and error_at_line().
56
57 If the global variable error_print_progname is assigned the address of
58 a function (i.e., is not NULL), then that function is called instead of
59 prefixing the message with the program name and colon. The function
60 should print a suitable string to stderr.
61
63 For an explanation of the terms used in this section, see at‐
64 tributes(7).
65
66 ┌────────────────┬───────────────┬─────────────────────────────────────┐
67 │Interface │ Attribute │ Value │
68 ├────────────────┼───────────────┼─────────────────────────────────────┤
69 │error() │ Thread safety │ MT-Safe locale │
70 ├────────────────┼───────────────┼─────────────────────────────────────┤
71 │error_at_line() │ Thread safety │ MT-Unsafe race: error_at_line/ │
72 │ │ │ error_one_per_line locale │
73 └────────────────┴───────────────┴─────────────────────────────────────┘
74
75 The internal error_one_per_line variable is accessed (without any form
76 of synchronization, but since it's an int used once, it should be safe
77 enough) and, if error_one_per_line is set nonzero, the internal static
78 variables (not exposed to users) used to hold the last printed filename
79 and line number are accessed and modified without synchronization; the
80 update is not atomic and it occurs before disabling cancelation, so it
81 can be interrupted only after one of the two variables is modified.
82 After that, error_at_line() is very much like error().
83
85 GNU.
86
88 err(3), errno(3), exit(3), perror(3), program_invocation_name(3),
89 strerror(3)
90
91
92
93Linux man-pages 6.05 2023-07-20 error(3)