OSDN Git Service

(split) LDP: Update original to LDP v3.65
[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 .\" %%%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 2010-08-29 "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
35 .BI "void error(int " status ", int " errnum ", const char *" format ", ...);"
36
37 .BI "void error_at_line(int " status ", int " errnum ", const char *" filename ,
38 .BI "                   unsigned int " linenum ", const char *" format ", ...);"
39
40 .BI "extern unsigned int " error_message_count ;
41
42 .BI "extern int " error_one_per_line ;
43
44 .BI "extern void (*" error_print_progname ") (void);"
45 .fi
46 .SH DESCRIPTION
47 .BR error ()
48 is a general error-reporting function.
49 It flushes
50 .IR stdout ,
51 and then outputs to
52 .I stderr
53 the program name, a colon and a space, the message specified by the
54 .BR printf (3)-style
55 format string \fIformat\fP, and, if \fIerrnum\fP is
56 nonzero, a second colon and a space followed by the string given by
57 .IR strerror(errnum) .
58 Any arguments required for
59 .I format
60 should follow
61 .I format
62 in the argument list.
63 The output is terminated by a newline character.
64
65 The program name printed by
66 .BR error ()
67 is the value of the global variable
68 .BR program_invocation_name (3).
69 .I program_invocation_name
70 initially has the same value as
71 .IR main ()'s
72 .IR argv[0] .
73 The value of this variable can be modified to change the output of
74 .BR error ().
75
76 If \fIstatus\fP has a nonzero value, then
77 .BR error ()
78 calls
79 .BR exit (3)
80 to terminate the program using the given value as the exit status.
81
82 The
83 .BR error_at_line ()
84 function is exactly the same as
85 .BR error (),
86 except for the addition of the arguments
87 .I filename
88 and
89 .IR linenum .
90 The output produced is as for
91 .BR error (),
92 except that after the program name are written: a colon, the value of
93 .IR filename ,
94 a colon, and the value of
95 .IR linenum .
96 The preprocessor values \fB__LINE__\fP and
97 \fB__FILE__\fP may be useful when calling
98 .BR error_at_line (),
99 but other values can also be used.
100 For example, these arguments could refer to a location in an input file.
101
102 If the global variable \fIerror_one_per_line\fP is set nonzero,
103 a sequence of
104 .BR error_at_line ()
105 calls with the
106 same value of \fIfilename\fP and \fIlinenum\fP will result in only
107 one message (the first) being output.
108
109 The global variable \fIerror_message_count\fP counts the number of
110 messages that have been output by
111 .BR error ()
112 and
113 .BR error_at_line ().
114
115 If the global variable \fIerror_print_progname\fP
116 is assigned the address of a function
117 (i.e., is not NULL), then that function is called
118 instead of prefixing the message with the program name and colon.
119 The function should print a suitable string to
120 .IR stderr .
121 .SH CONFORMING TO
122 These functions and variables are GNU extensions, and should not be
123 used in programs intended to be portable.
124 .SH SEE ALSO
125 .BR err (3),
126 .BR errno (3),
127 .BR exit (3),
128 .BR perror (3),
129 .BR program_invocation_name (3),
130 .BR strerror (3)
131 .SH COLOPHON
132 This page is part of release 3.65 of the Linux
133 .I man-pages
134 project.
135 A description of the project,
136 and information about reporting bugs,
137 can be found at
138 \%http://www.kernel.org/doc/man\-pages/.