1 .\" $NetBSD: err.3,v 1.20 2010/03/22 19:30:53 joerg 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
44 .Nd formatted error messages
50 .Fn err "int status" "const char *fmt" "..."
52 .Fn verr "int status" "const char *fmt" "va_list args"
54 .Fn errx "int status" "const char *fmt" "..."
56 .Fn verrx "int status" "const char *fmt" "va_list args"
58 .Fn warn "const char *fmt" "..."
60 .Fn vwarn "const char *fmt" "va_list args"
62 .Fn warnx "const char *fmt" "..."
64 .Fn vwarnx "const char *fmt" "va_list args"
70 family of functions display a formatted error message on the standard
72 In all cases, the last component of the program name, a colon character,
73 and a space are output.
78 the formatted error message is output.
85 functions, the error message string affiliated with the current value of
88 is output next, preceded by a colon character and a space if
92 In all cases, the output is followed by a newline character.
99 functions will not output this error message string.
107 functions do not return, but instead cause the program to terminate
108 with the status value given by the argument
110 It is often appropriate to use the value
116 argument given to these functions.
120 information string and terminate with status indicating failure:
121 .Bd -literal -offset indent
122 if ((p = malloc(size)) == NULL)
123 err(EXIT_FAILURE, NULL);
124 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
125 err(EXIT_FAILURE, "%s", file_name);
128 Display an error message and terminate with status indicating failure:
129 .Bd -literal -offset indent
130 if (tm.tm_hour \*[Lt] START_TIME)
131 errx(EXIT_FAILURE, "too early, wait until %s",
136 .Bd -literal -offset indent
137 if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
138 warnx("%s: %s: trying the block device",
139 raw_device, strerror(errno));
140 if ((fd = open(block_device, O_RDONLY, 0)) == -1)
141 warn("%s", block_device);
152 functions first appeared in
155 It is important never to pass a string with user-supplied data as a
158 An attacker can put format specifiers in the string to mangle your stack,
159 leading to a possible security hole.
160 This holds true even if you have built the string
162 using a function like
164 as the resulting string may still contain user-supplied conversion specifiers
165 for later interpolation by the
171 Always be sure to use the proper secure idiom:
172 .Bd -literal -offset indent
173 err(1, "%s", string);