]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/error.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / error.3
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 (date) "Linux man-pages (unreleased)"
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 LIBRARY
32 Standard C library
33 .RI ( libc ", " \-lc )
34 .SH SYNOPSIS
35 .nf
36 .B #include <error.h>
37 .PP
38 .BI "void error(int " status ", int " errnum ", const char *" format ", ...);"
39 .BI "void error_at_line(int " status ", int " errnum ", const char *" filename ,
40 .BI " unsigned int " linenum ", const char *" format ", ...);"
41 .PP
42 .BI "extern unsigned int " error_message_count ;
43 .BI "extern int " error_one_per_line ;
44 .PP
45 .BI "extern void (*" error_print_progname ")(void);"
46 .fi
47 .SH DESCRIPTION
48 .BR error ()
49 is a general error-reporting function.
50 It flushes
51 .IR stdout ,
52 and then outputs to
53 .I stderr
54 the program name, a colon and a space, the message specified by the
55 .BR printf (3)-style
56 format string \fIformat\fP, and, if \fIerrnum\fP is
57 nonzero, a second colon and a space followed by the string given by
58 .IR strerror(errnum) .
59 Any arguments required for
60 .I format
61 should follow
62 .I format
63 in the argument list.
64 The output is terminated by a newline character.
65 .PP
66 The program name printed by
67 .BR error ()
68 is the value of the global variable
69 .BR program_invocation_name (3).
70 .I program_invocation_name
71 initially has the same value as
72 .IR main ()'s
73 .IR argv[0] .
74 The value of this variable can be modified to change the output of
75 .BR error ().
76 .PP
77 If \fIstatus\fP has a nonzero value, then
78 .BR error ()
79 calls
80 .BR exit (3)
81 to terminate the program using the given value as the exit status;
82 otherwise it returns after printing the error message.
83 .PP
84 The
85 .BR error_at_line ()
86 function is exactly the same as
87 .BR error (),
88 except for the addition of the arguments
89 .I filename
90 and
91 .IR linenum .
92 The output produced is as for
93 .BR error (),
94 except that after the program name are written: a colon, the value of
95 .IR filename ,
96 a colon, and the value of
97 .IR linenum .
98 The preprocessor values \fB__LINE__\fP and
99 \fB__FILE__\fP may be useful when calling
100 .BR error_at_line (),
101 but other values can also be used.
102 For example, these arguments could refer to a location in an input file.
103 .PP
104 If the global variable \fIerror_one_per_line\fP is set nonzero,
105 a sequence of
106 .BR error_at_line ()
107 calls with the
108 same value of \fIfilename\fP and \fIlinenum\fP will result in only
109 one message (the first) being output.
110 .PP
111 The global variable \fIerror_message_count\fP counts the number of
112 messages that have been output by
113 .BR error ()
114 and
115 .BR error_at_line ().
116 .PP
117 If the global variable \fIerror_print_progname\fP
118 is assigned the address of a function
119 (i.e., is not NULL), then that function is called
120 instead of prefixing the message with the program name and colon.
121 The function should print a suitable string to
122 .IR stderr .
123 .SH ATTRIBUTES
124 For an explanation of the terms used in this section, see
125 .BR attributes (7).
126 .ad l
127 .nh
128 .TS
129 allbox;
130 lb lb lbx
131 l l l.
132 Interface Attribute Value
133 T{
134 .BR error ()
135 T} Thread safety MT-Safe locale
136 T{
137 .BR error_at_line ()
138 T} Thread safety T{
139 MT-Unsafe\ race: error_at_line/\:error_one_per_line locale
140 T}
141 .TE
142 .hy
143 .ad
144 .sp 1
145 .PP
146 The internal
147 .I error_one_per_line
148 variable is accessed (without any form of synchronization, but since it's an
149 .I int
150 used once, it should be safe enough) and, if
151 .I error_one_per_line
152 is set nonzero, the internal static variables (not exposed to users)
153 used to hold the last printed filename and line number are accessed
154 and modified without synchronization; the update is not atomic and it
155 occurs before disabling cancelation, so it can be interrupted only after
156 one of the two variables is modified.
157 After that,
158 .BR error_at_line ()
159 is very much like
160 .BR error ().
161 .SH STANDARDS
162 These functions and variables are GNU extensions, and should not be
163 used in programs intended to be portable.
164 .SH SEE ALSO
165 .BR err (3),
166 .BR errno (3),
167 .BR exit (3),
168 .BR perror (3),
169 .BR program_invocation_name (3),
170 .BR strerror (3)