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