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