1 '\" te
2 .\" Copyright (c) 1996-2001 Wolfram Schneider. Berlin.
3 .\" Copyright (c) 1993-1995 Berkeley Software Design, Inc.
4 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH ERR 3C "Aug 20, 2007"
9 .SH NAME
10 err, verr, errx, verrx, warn, vwarn, warnx, vwarnx \- formatted error messages
11 .SH SYNOPSIS
12 .LP
13 .nf
14 #include <err.h>
15
16 \fBvoid\fR \fBerr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...);
17 .fi
18
19 .LP
20 .nf
21 \fBvoid\fR \fBverr\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
22 .fi
23
24 .LP
25 .nf
26 \fBvoid\fR \fBerrx\fR(\fBint\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, ...);
27 .fi
28
29 .LP
30 .nf
31 \fBvoid\fR \fBverrx\fR\fB(int\fR \fIeval\fR, \fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
32 .fi
33
34 .LP
35 .nf
36 \fBvoid\fR \fBwarn\fR(\fBconst char *\fR\fIfmt\fR, ...);
37 .fi
38
39 .LP
40 .nf
41 \fBvoid\fR \fBvwarn\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
42 .fi
43
44 .LP
45 .nf
46 \fBvoid\fR \fBwarnx\fR(\fBconst char *\fR\fIfmt\fR, ...);
47 .fi
48
49 .LP
50 .nf
51 \fBvoid\fR \fBvwarnx\fR(\fBconst char *\fR\fIfmt\fR, \fBva_list\fR \fIargs\fR);
52 .fi
53
54 .SH DESCRIPTION
55 .sp
56 .LP
57 The \fBerr()\fR and \fBwarn()\fR family of functions display a formatted error
58 message on the standard error output. In all cases, the last component of the
59 program name, followed by a colon character and a space, are output. If the
60 \fIfmt\fR argument is not \fINULL\fR, the formatted error message is output. In
61 the case of the \fBerr()\fR, \fBverr()\fR, \fBwarn()\fR, and \fBvwarn()\fR
62 functions, the error message string affiliated with the current value of the
63 global variable \fBerrno\fR is output next, preceded by a colon character and a
64 space if \fIfmt\fR is not \fINULL\fR. In all cases, the output is followed by a
65 newline character. The \fBerrx()\fR, \fBverrx()\fR, \fBwarnx()\fR, and
66 \fBvwarnx()\fR functions will not output this error message string.
67 .sp
68 .LP
69 The \fBerr()\fR, \fBverr()\fR, \fBerrx()\fR, and \fBverrx()\fR functions do not
70 return, but instead cause the program to terminate with the status value given
71 by the argument \fIeval\fR.
72 .SH EXAMPLES
73 .LP
74 \fBExample 1 \fRDisplay the current \fBerrno\fR information string and
75 terminate with status indicating failure.
76 .sp
77 .in +2
78 .nf
79 if ((p = malloc(size)) == NULL)
80 err(EXIT_FAILURE, NULL);
81 if ((fd = open(file_name, O_RDONLY, 0)) == -1)
82 err(EXIT_FAILURE, "%s", file_name);
83 .fi
84 .in -2
85
86 .LP
87 \fBExample 2 \fRDisplay an error message and terminate with status indicating
88 failure.
89 .sp
90 .in +2
91 .nf
92 if (tm.tm_hour < START_TIME)
93 errx(EXIT_FAILURE, "too early, wait until %s", start_time_string);
94 .fi
95 .in -2
96
97 .LP
98 \fBExample 3 \fRWarn of an error.
99 .sp
100 .in +2
101 .nf
102 if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
103 warnx("%s: %s: trying the block device",
104 raw_device, strerror(errno));
105 if ((fd = open(block_device, O_RDONLY, 0)) == -1)
106 warn("%s", block_device);
107 .fi
108 .in -2
109
110 .SH WARNINGS
111 .sp
112 .LP
113 It is important never to pass a string with user-supplied data as a format
114 without using `%s'. An attacker can put format specifiers in the string to
115 mangle the stack, leading to a possible security hole. This holds true even if
116 the string has been built ``by hand'' using a function like \fBsnprintf\fR(3C),
117 as the resulting string can still contain user-supplied conversion specifiers
118 for later interpolation by the \fBerr()\fR and \fBwarn()\fR functions.
119 .sp
120 .LP
121 Always be sure to use the proper secure idiom:
122 .sp
123 .in +2
124 .nf
125 err(1, "%s", string);
126 .fi
127 .in -2
128
129 .SH ATTRIBUTES
130 .sp
131 .LP
132 See \fBattributes\fR(5) for descriptions of the following attributes:
133 .sp
134
135 .sp
136 .TS
137 box;
138 c | c
139 l | l .
140 ATTRIBUTE TYPE ATTRIBUTE VALUE
141 _
142 Interface Stability Committed
143 _
144 MT-Level Safe with Exceptions
145 .TE
146
147 .sp
148 .LP
149 These functions are safe to use in multithreaded applications as long as
150 \fBsetlocale\fR(3C) is not being called to change the locale.
151 .SH SEE ALSO
152 .sp
153 .LP
154 \fBexit\fR(3C), \fBgetexecname\fR(3C), \fBsetlocale\fR(3C), \fBstrerror\fR(3C),
155 \fBattributes\fR(5)