| 1 |
'\" t |
| 2 |
.\" Copyright (C) 2006 Justin Pryzby <[email protected]> |
| 3 |
.\" and Copyright (C) 2006 Michael Kerrisk <[email protected]> |
| 4 |
.\" |
| 5 |
.\" %%%LICENSE_START(PERMISSIVE_MISC) |
| 6 |
.\" Permission is hereby granted, free of charge, to any person obtaining |
| 7 |
.\" a copy of this software and associated documentation files (the |
| 8 |
.\" "Software"), to deal in the Software without restriction, including |
| 9 |
.\" without limitation the rights to use, copy, modify, merge, publish, |
| 10 |
.\" distribute, sublicense, and/or sell copies of the Software, and to |
| 11 |
.\" permit persons to whom the Software is furnished to do so, subject to |
| 12 |
.\" the following conditions: |
| 13 |
.\" |
| 14 |
.\" The above copyright notice and this permission notice shall be |
| 15 |
.\" included in all copies or substantial portions of the Software. |
| 16 |
.\" |
| 17 |
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 |
.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 |
.\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 |
.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 |
.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 |
.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
.\" %%%LICENSE_END |
| 25 |
.\" |
| 26 |
.\" References: |
| 27 |
.\" glibc manual and source |
| 28 |
.TH error 3 2024-05-02 "Linux man-pages 6.9.1" |
| 29 |
.SH NAME |
| 30 |
error, error_at_line, error_message_count, error_one_per_line, |
| 31 |
error_print_progname \- glibc error reporting functions |
| 32 |
.SH LIBRARY |
| 33 |
Standard C library |
| 34 |
.RI ( libc ", " \-lc ) |
| 35 |
.SH SYNOPSIS |
| 36 |
.nf |
| 37 |
.B #include <error.h> |
| 38 |
.P |
| 39 |
.BI "void error(int " status ", int " errnum ", const char *" format ", ...);" |
| 40 |
.BI "void error_at_line(int " status ", int " errnum ", const char *" filename , |
| 41 |
.BI " unsigned int " linenum ", const char *" format ", ...);" |
| 42 |
.P |
| 43 |
.BI "extern unsigned int " error_message_count ; |
| 44 |
.BI "extern int " error_one_per_line ; |
| 45 |
.P |
| 46 |
.BI "extern void (*" error_print_progname ")(void);" |
| 47 |
.fi |
| 48 |
.SH DESCRIPTION |
| 49 |
.BR error () |
| 50 |
is a general error-reporting function. |
| 51 |
It flushes |
| 52 |
.IR stdout , |
| 53 |
and then outputs to |
| 54 |
.I stderr |
| 55 |
the program name, a colon and a space, the message specified by the |
| 56 |
.BR printf (3)-style |
| 57 |
format string \fIformat\fP, and, if \fIerrnum\fP is |
| 58 |
nonzero, a second colon and a space followed by the string given by |
| 59 |
.IR strerror(errnum) . |
| 60 |
Any arguments required for |
| 61 |
.I format |
| 62 |
should follow |
| 63 |
.I format |
| 64 |
in the argument list. |
| 65 |
The output is terminated by a newline character. |
| 66 |
.P |
| 67 |
The program name printed by |
| 68 |
.BR error () |
| 69 |
is the value of the global variable |
| 70 |
.BR program_invocation_name (3). |
| 71 |
.I program_invocation_name |
| 72 |
initially has the same value as |
| 73 |
.IR main ()'s |
| 74 |
.IR argv[0] . |
| 75 |
The value of this variable can be modified to change the output of |
| 76 |
.BR error (). |
| 77 |
.P |
| 78 |
If \fIstatus\fP has a nonzero value, then |
| 79 |
.BR error () |
| 80 |
calls |
| 81 |
.BR exit (3) |
| 82 |
to terminate the program using the given value as the exit status; |
| 83 |
otherwise it returns after printing the error message. |
| 84 |
.P |
| 85 |
The |
| 86 |
.BR error_at_line () |
| 87 |
function is exactly the same as |
| 88 |
.BR error (), |
| 89 |
except for the addition of the arguments |
| 90 |
.I filename |
| 91 |
and |
| 92 |
.IR linenum . |
| 93 |
The output produced is as for |
| 94 |
.BR error (), |
| 95 |
except that after the program name are written: a colon, the value of |
| 96 |
.IR filename , |
| 97 |
a colon, and the value of |
| 98 |
.IR linenum . |
| 99 |
The preprocessor values \fB__LINE__\fP and |
| 100 |
\fB__FILE__\fP may be useful when calling |
| 101 |
.BR error_at_line (), |
| 102 |
but other values can also be used. |
| 103 |
For example, these arguments could refer to a location in an input file. |
| 104 |
.P |
| 105 |
If the global variable \fIerror_one_per_line\fP is set nonzero, |
| 106 |
a sequence of |
| 107 |
.BR error_at_line () |
| 108 |
calls with the |
| 109 |
same value of \fIfilename\fP and \fIlinenum\fP will result in only |
| 110 |
one message (the first) being output. |
| 111 |
.P |
| 112 |
The global variable \fIerror_message_count\fP counts the number of |
| 113 |
messages that have been output by |
| 114 |
.BR error () |
| 115 |
and |
| 116 |
.BR error_at_line (). |
| 117 |
.P |
| 118 |
If the global variable \fIerror_print_progname\fP |
| 119 |
is assigned the address of a function |
| 120 |
(i.e., is not NULL), then that function is called |
| 121 |
instead of prefixing the message with the program name and colon. |
| 122 |
The function should print a suitable string to |
| 123 |
.IR stderr . |
| 124 |
.SH ATTRIBUTES |
| 125 |
For an explanation of the terms used in this section, see |
| 126 |
.BR attributes (7). |
| 127 |
.TS |
| 128 |
allbox; |
| 129 |
lb lb lbx |
| 130 |
l l l. |
| 131 |
Interface Attribute Value |
| 132 |
T{ |
| 133 |
.na |
| 134 |
.nh |
| 135 |
.BR error () |
| 136 |
T} Thread safety MT-Safe locale |
| 137 |
T{ |
| 138 |
.na |
| 139 |
.nh |
| 140 |
.BR error_at_line () |
| 141 |
T} Thread safety T{ |
| 142 |
.na |
| 143 |
.nh |
| 144 |
MT-Unsafe\ race: error_at_line/\:error_one_per_line locale |
| 145 |
T} |
| 146 |
.TE |
| 147 |
.P |
| 148 |
The internal |
| 149 |
.I error_one_per_line |
| 150 |
variable is accessed (without any form of synchronization, but since it's an |
| 151 |
.I int |
| 152 |
used once, it should be safe enough) and, if |
| 153 |
.I error_one_per_line |
| 154 |
is set nonzero, the internal static variables (not exposed to users) |
| 155 |
used to hold the last printed filename and line number are accessed |
| 156 |
and modified without synchronization; the update is not atomic and it |
| 157 |
occurs before disabling cancelation, so it can be interrupted only after |
| 158 |
one of the two variables is modified. |
| 159 |
After that, |
| 160 |
.BR error_at_line () |
| 161 |
is very much like |
| 162 |
.BR error (). |
| 163 |
.SH STANDARDS |
| 164 |
GNU. |
| 165 |
.SH SEE ALSO |
| 166 |
.BR err (3), |
| 167 |
.BR errno (3), |
| 168 |
.BR exit (3), |
| 169 |
.BR perror (3), |
| 170 |
.BR program_invocation_name (3), |
| 171 |
.BR strerror (3) |