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