]>
Commit | Line | Data |
---|---|---|
e9ce8d39 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1993 | |
24 | * The Regents of the University of California. All rights reserved. | |
25 | * | |
26 | * Redistribution and use in source and binary forms, with or without | |
27 | * modification, are permitted provided that the following conditions | |
28 | * are met: | |
29 | * 1. Redistributions of source code must retain the above copyright | |
30 | * notice, this list of conditions and the following disclaimer. | |
31 | * 2. Redistributions in binary form must reproduce the above copyright | |
32 | * notice, this list of conditions and the following disclaimer in the | |
33 | * documentation and/or other materials provided with the distribution. | |
34 | * 3. All advertising materials mentioning features or use of this software | |
35 | * must display the following acknowledgement: | |
36 | * This product includes software developed by the University of | |
37 | * California, Berkeley and its contributors. | |
38 | * 4. Neither the name of the University nor the names of its contributors | |
39 | * may be used to endorse or promote products derived from this software | |
40 | * without specific prior written permission. | |
41 | * | |
42 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
43 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
44 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
45 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
46 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
47 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
48 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
50 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
51 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
52 | * SUCH DAMAGE. | |
53 | */ | |
54 | ||
55 | ||
56 | #include <err.h> | |
57 | #include <errno.h> | |
58 | #include <stdio.h> | |
59 | #include <stdlib.h> | |
60 | #include <string.h> | |
61 | ||
62 | #include <crt_externs.h> | |
63 | ||
64 | #ifdef __STDC__ | |
65 | #include <stdarg.h> | |
66 | #else | |
67 | #include <varargs.h> | |
68 | #endif | |
69 | ||
70 | __dead void | |
71 | #ifdef __STDC__ | |
72 | err(int eval, const char *fmt, ...) | |
73 | #else | |
74 | err(eval, fmt, va_alist) | |
75 | int eval; | |
76 | const char *fmt; | |
77 | va_dcl | |
78 | #endif | |
79 | { | |
80 | va_list ap; | |
81 | #if __STDC__ | |
82 | va_start(ap, fmt); | |
83 | #else | |
84 | va_start(ap); | |
85 | #endif | |
86 | verr(eval, fmt, ap); | |
87 | va_end(ap); | |
88 | } | |
89 | ||
90 | __dead void | |
91 | verr(eval, fmt, ap) | |
92 | int eval; | |
93 | const char *fmt; | |
94 | va_list ap; | |
95 | { | |
96 | char* __progname = *(*_NSGetArgv()); | |
97 | int sverrno; | |
98 | ||
99 | sverrno = errno; | |
100 | (void)fprintf(stderr, "%s: ", __progname); | |
101 | if (fmt != NULL) { | |
102 | (void)vfprintf(stderr, fmt, ap); | |
103 | (void)fprintf(stderr, ": "); | |
104 | } | |
105 | (void)fprintf(stderr, "%s\n", strerror(sverrno)); | |
106 | exit(eval); | |
107 | } | |
108 | ||
109 | __dead void | |
110 | #if __STDC__ | |
111 | errx(int eval, const char *fmt, ...) | |
112 | #else | |
113 | errx(eval, fmt, va_alist) | |
114 | int eval; | |
115 | const char *fmt; | |
116 | va_dcl | |
117 | #endif | |
118 | { | |
119 | va_list ap; | |
120 | #if __STDC__ | |
121 | va_start(ap, fmt); | |
122 | #else | |
123 | va_start(ap); | |
124 | #endif | |
125 | verrx(eval, fmt, ap); | |
126 | va_end(ap); | |
127 | } | |
128 | ||
129 | __dead void | |
130 | verrx(eval, fmt, ap) | |
131 | int eval; | |
132 | const char *fmt; | |
133 | va_list ap; | |
134 | { | |
135 | char* __progname = *(*_NSGetArgv()); | |
136 | (void)fprintf(stderr, "%s: ", __progname); | |
137 | if (fmt != NULL) | |
138 | (void)vfprintf(stderr, fmt, ap); | |
139 | (void)fprintf(stderr, "\n"); | |
140 | exit(eval); | |
141 | } | |
142 | ||
143 | void | |
144 | #if __STDC__ | |
145 | warn(const char *fmt, ...) | |
146 | #else | |
147 | warn(fmt, va_alist) | |
148 | const char *fmt; | |
149 | va_dcl | |
150 | #endif | |
151 | { | |
152 | va_list ap; | |
153 | #if __STDC__ | |
154 | va_start(ap, fmt); | |
155 | #else | |
156 | va_start(ap); | |
157 | #endif | |
158 | vwarn(fmt, ap); | |
159 | va_end(ap); | |
160 | } | |
161 | ||
162 | void | |
163 | vwarn(fmt, ap) | |
164 | const char *fmt; | |
165 | va_list ap; | |
166 | { | |
167 | int sverrno = errno; | |
168 | char* __progname = *(*_NSGetArgv()); | |
169 | (void)fprintf(stderr, "%s: ", __progname); | |
170 | if (fmt != NULL) { | |
171 | (void)vfprintf(stderr, fmt, ap); | |
172 | (void)fprintf(stderr, ": "); | |
173 | } | |
174 | (void)fprintf(stderr, "%s\n", strerror(sverrno)); | |
175 | } | |
176 | ||
177 | void | |
178 | #ifdef __STDC__ | |
179 | warnx(const char *fmt, ...) | |
180 | #else | |
181 | warnx(fmt, va_alist) | |
182 | const char *fmt; | |
183 | va_dcl | |
184 | #endif | |
185 | { | |
186 | va_list ap; | |
187 | #ifdef __STDC__ | |
188 | va_start(ap, fmt); | |
189 | #else | |
190 | va_start(ap); | |
191 | #endif | |
192 | vwarnx(fmt, ap); | |
193 | va_end(ap); | |
194 | } | |
195 | ||
196 | void | |
197 | vwarnx(fmt, ap) | |
198 | const char *fmt; | |
199 | va_list ap; | |
200 | { | |
201 | char* __progname = *(*_NSGetArgv()); | |
202 | (void)fprintf(stderr, "%s: ", __progname); | |
203 | if (fmt != NULL) | |
204 | (void)vfprintf(stderr, fmt, ap); | |
205 | (void)fprintf(stderr, "\n"); | |
206 | } |