|
1 /*- |
|
2 * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved. |
|
3 * Copyright (c) 1993 |
|
4 * The Regents of the University of California. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
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. All advertising materials mentioning features or use of this software |
|
15 * must display the following acknowledgement: |
|
16 * This product includes software developed by the University of |
|
17 * California, Berkeley and its contributors. |
|
18 * 4. Neither the name of the University nor the names of its contributors |
|
19 * may be used to endorse or promote products derived from this software |
|
20 * without specific prior written permission. |
|
21 * |
|
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
32 * SUCH DAMAGE. |
|
33 */ |
|
34 |
|
35 #if defined(LIBC_SCCS) && !defined(lint) |
|
36 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; |
|
37 #endif /* LIBC_SCCS and not lint */ |
|
38 #include <sys/cdefs.h> |
|
39 __FBSDID("$FreeBSD: src/lib/libc/gen/err.c,v 1.13 2002/03/29 22:43:41 markm Exp $"); |
|
40 |
|
41 |
|
42 #include <err.h> |
|
43 #include <errno.h> |
|
44 #include <stdarg.h> |
|
45 #include <stdio.h> |
|
46 #include <stdlib.h> |
|
47 #include <string.h> |
|
48 |
|
49 #ifdef __SYMBIAN32__ |
|
50 #ifdef __WINSCW__ |
|
51 #pragma warn_unusedarg off |
|
52 #endif////__WINSCW__ |
|
53 #ifdef __ARMCC__ |
|
54 // Turn off the 'extended constant initialiser used' warning |
|
55 #pragma diag_remark 1294 |
|
56 #endif//__ARMCC__ |
|
57 #endif//__SYMBIAN32__ |
|
58 |
|
59 #ifndef EMULATOR |
|
60 |
|
61 static FILE *err_file; /* file to use for error output */ |
|
62 |
|
63 #ifdef __SYMBIAN_COMPILE_UNUSED__ |
|
64 static void (*err_exit)(int); |
|
65 #endif |
|
66 |
|
67 #else //EMULATOR |
|
68 |
|
69 GET_STATIC_VAR_FROM_TLS(err_file, FILE *) |
|
70 |
|
71 #define err_file (*GET_WSD_VAR_NAME(err_file, s)()) |
|
72 |
|
73 #ifdef __SYMBIAN_COMPILE_UNUSED__ |
|
74 #define err_exit (GetGlobals()->_s_err_exit) |
|
75 #endif |
|
76 |
|
77 |
|
78 #endif //EMULATOR |
|
79 |
|
80 /* |
|
81 * This is declared to take a `void *' so that the caller is not required |
|
82 * to include <stdio.h> first. However, it is really a `FILE *', and the |
|
83 * manual page documents it as such. |
|
84 */ |
|
85 void |
|
86 err_set_file(void *fp) |
|
87 { |
|
88 if (fp) |
|
89 err_file = fp; |
|
90 else |
|
91 err_file = stderr; |
|
92 } |
|
93 |
|
94 #ifndef __SYMBIAN32__ |
|
95 void |
|
96 err_set_exit(void (*ef)(int)) |
|
97 { |
|
98 err_exit = ef; |
|
99 } |
|
100 #endif |
|
101 |
|
102 void |
|
103 err(int eval, const char *fmt, ...) |
|
104 { |
|
105 va_list ap; |
|
106 va_start(ap, fmt); |
|
107 verrc(eval, errno, fmt, ap); |
|
108 va_end(ap); |
|
109 } |
|
110 |
|
111 void |
|
112 verr(eval, fmt, ap) |
|
113 int eval; |
|
114 const char *fmt; |
|
115 va_list ap; |
|
116 { |
|
117 verrc(eval, errno, fmt, ap); |
|
118 } |
|
119 |
|
120 void |
|
121 errc(int eval, int code, const char *fmt, ...) |
|
122 { |
|
123 va_list ap; |
|
124 va_start(ap, fmt); |
|
125 verrc(eval, code, fmt, ap); |
|
126 va_end(ap); |
|
127 } |
|
128 |
|
129 void |
|
130 verrc(eval, code, fmt, ap) |
|
131 int eval; |
|
132 int code; |
|
133 const char *fmt; |
|
134 va_list ap; |
|
135 { |
|
136 if (fmt != NULL) { |
|
137 vprintf(fmt, ap); |
|
138 printf(": "); |
|
139 } |
|
140 printf("%s\n", strerror(code)); |
|
141 } |
|
142 |
|
143 void |
|
144 errx(int eval, const char *fmt, ...) |
|
145 { |
|
146 va_list ap; |
|
147 va_start(ap, fmt); |
|
148 verrx(eval, fmt, ap); |
|
149 va_end(ap); |
|
150 } |
|
151 |
|
152 void |
|
153 verrx(eval, fmt, ap) |
|
154 int eval; |
|
155 const char *fmt; |
|
156 va_list ap; |
|
157 { |
|
158 if (fmt != NULL) |
|
159 vprintf(fmt, ap); |
|
160 printf("\n"); |
|
161 } |
|
162 |
|
163 |
|
164 void |
|
165 warn(const char *fmt, ...) |
|
166 { |
|
167 va_list ap; |
|
168 va_start(ap, fmt); |
|
169 vwarnc(errno, fmt, ap); |
|
170 va_end(ap); |
|
171 } |
|
172 |
|
173 void |
|
174 vwarn(fmt, ap) |
|
175 const char *fmt; |
|
176 va_list ap; |
|
177 { |
|
178 vwarnc(errno, fmt, ap); |
|
179 } |
|
180 |
|
181 void |
|
182 warnc(int code, const char *fmt, ...) |
|
183 { |
|
184 va_list ap; |
|
185 va_start(ap, fmt); |
|
186 vwarnc(code, fmt, ap); |
|
187 va_end(ap); |
|
188 } |
|
189 |
|
190 void |
|
191 vwarnc(code, fmt, ap) |
|
192 int code; |
|
193 const char *fmt; |
|
194 va_list ap; |
|
195 { |
|
196 if (fmt != NULL) { |
|
197 vprintf(fmt, ap); |
|
198 printf(": "); |
|
199 } |
|
200 printf("%s\n", strerror(code)); |
|
201 } |
|
202 |
|
203 void |
|
204 warnx(const char *fmt, ...) |
|
205 { |
|
206 va_list ap; |
|
207 va_start(ap, fmt); |
|
208 vwarnx(fmt, ap); |
|
209 va_end(ap); |
|
210 } |
|
211 |
|
212 void |
|
213 vwarnx(fmt, ap) |
|
214 const char *fmt; |
|
215 va_list ap; |
|
216 { |
|
217 if (fmt != NULL) |
|
218 vprintf(fmt, ap); |
|
219 printf("\n"); |
|
220 } |