OSDN Git Service

95bd57bfc23224e51bc52d1278724cc84608d415
[linuxjm/LDP_man-pages.git] / original / 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 .\" Permission is hereby granted, free of charge, to any person obtaining
5 .\" a copy of this software and associated documentation files (the
6 .\" "Software"), to deal in the Software without restriction, including
7 .\" without limitation the rights to use, copy, modify, merge, publish,
8 .\" distribute, sublicense, and/or sell copies of the Software, and to
9 .\" permit persons to whom the Software is furnished to do so, subject to
10 .\" the following conditions:
11 .\"
12 .\" The above copyright notice and this permission notice shall be
13 .\" included in all copies or substantial portions of the Software.
14 .\"
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 .\"
23 .\" References:
24 .\"   glibc manual and source
25 .TH ERROR 3 2010-08-29 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 error, error_at_line, error_message_count, error_one_per_line,
28 error_print_progname \- glibc error reporting functions
29 .SH SYNOPSIS
30 .nf
31 \fB#include <error.h>
32
33 \fBvoid error(int \fIstatus, \fBint\fI errnum, \
34 \fBconst char *\fIformat, \fB...);
35
36 \fBvoid error_at_line(int \fIstatus, \fBint \fIerrnum, \
37 \fBconst char *\fIfilename,
38                    \fBunsigned int \fIlinenum, \
39 \fBconst char *\fIformat, \fB...);
40
41 \fBextern unsigned int \fIerror_message_count\fP;
42
43 \fBextern int \fIerror_one_per_line\fP;
44
45 \fBextern void (* \fIerror_print_progname\fB) (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
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
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
83 The
84 .BR error_at_line ()
85 function is exactly the same as
86 .BR error (),
87 except for the addition of the arguments
88 .I filename
89 and
90 .IR linenum .
91 The output produced is as for
92 .BR error (),
93 except that after the program name are written: a colon, the value of
94 .IR filename ,
95 a colon, and the value of
96 .IR linenum .
97 The preprocessor values \fB__LINE__\fP and
98 \fB__FILE__\fP may be useful when calling
99 .BR error_at_line (),
100 but other values can also be used.
101 For example, these arguments could refer to a location in an input file.
102
103 If the global variable \fIerror_one_per_line\fP is set nonzero,
104 a sequence of
105 .BR error_at_line ()
106 calls with the
107 same value of \fIfilename\fP and \fIlinenum\fP will result in only
108 one message (the first) being output.
109
110 The global variable \fIerror_message_count\fP counts the number of
111 messages that have been output by
112 .BR error ()
113 and
114 .BR error_at_line ().
115
116 If the global variable \fIerror_print_progname\fP
117 is assigned the address of a function
118 (i.e., is not NULL), then that function is called
119 instead of prefixing the message with the program name and colon.
120 The function should print a suitable string to
121 .IR stderr .
122 .SH "CONFORMING TO"
123 These functions and variables are GNU extensions, and should not be
124 used in programs intended to be portable.
125 .SH SEE ALSO
126 .BR err (3),
127 .BR errno (3),
128 .BR exit (3),
129 .BR perror (3),
130 .BR program_invocation_name (3),
131 .BR strerror (3)