1 .\" $NetBSD: err.3,v 1.21 2014/01/16 17:21:38 christos Exp $
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)err.3 8.1 (Berkeley) 6/9/93
48 .Nd formatted error messages
54 .Fn err "int status" "const char *fmt" "..."
56 .Fn verr "int status" "const char *fmt" "va_list args"
58 .Fn errx "int status" "const char *fmt" "..."
60 .Fn verrx "int status" "const char *fmt" "va_list args"
62 .Fn errc "int status" "int code" "const char *fmt" "..."
64 .Fn verrc "int status" "int code" "const char *fmt" "va_list args"
66 .Fn warn "const char *fmt" "..."
68 .Fn vwarn "const char *fmt" "va_list args"
70 .Fn warnx "const char *fmt" "..."
72 .Fn vwarnx "const char *fmt" "va_list args"
74 .Fn warnc "int code" "const char *fmt" "..."
76 .Fn vwarnc "int code" "const char *fmt" "va_list args"
82 family of functions display a formatted error message on the standard
84 In all cases, the last component of the program name, a colon character,
85 and a space are output.
90 the formatted error message is output.
97 functions, the error message string affiliated with the current value of
100 is output next, preceded by a colon character and a space if
104 In all cases, the output is followed by a newline character.
111 functions take an additional
113 argument to be used as the error number instead of using the global
122 functions will not output this error message string.
130 functions do not return, but instead cause the program to terminate
131 with the status value given by the argument
133 It is often appropriate to use the value
139 argument given to these functions.
143 information string and terminate with status indicating failure:
144 .Bd -literal -offset indent
145 if ((p = malloc(size)) == NULL)
146 err(EXIT_FAILURE, NULL);
147 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
148 err(EXIT_FAILURE, "%s", file_name);
151 Display an error message and terminate with status indicating failure:
152 .Bd -literal -offset indent
153 if (tm.tm_hour \*[Lt] START_TIME)
154 errx(EXIT_FAILURE, "too early, wait until %s",
159 .Bd -literal -offset indent
160 if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
161 warnx("%s: %s: trying the block device",
162 raw_device, strerror(errno));
163 if ((fd = open(block_device, O_RDONLY, 0)) == -1)
164 warn("%s", block_device);
175 functions first appeared in
181 functions first appeared in
186 It is important never to pass a string with user-supplied data as a
189 An attacker can put format specifiers in the string to mangle your stack,
190 leading to a possible security hole.
191 This holds true even if you have built the string
193 using a function like
195 as the resulting string may still contain user-supplied conversion specifiers
196 for later interpolation by the
202 Always be sure to use the proper secure idiom:
203 .Bd -literal -offset indent
204 err(1, "%s", string);