[d48955b] | 1 | #include <machine/rtems-bsd-user-space.h> |
---|
| 2 | |
---|
[9054adf] | 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 | |
---|
[d01564c] | 49 | #ifndef __rtems__ |
---|
[9054adf] | 50 | static FILE *err_file; /* file to use for error output */ |
---|
| 51 | static void (*err_exit)(int); |
---|
[d01564c] | 52 | #else /* __rtems__ */ |
---|
| 53 | #include <machine/rtems-bsd-program.h> |
---|
| 54 | #define err_file stderr |
---|
| 55 | #define err_set_file(x) do { } while (0) |
---|
| 56 | #endif /* __rtems__ */ |
---|
[9054adf] | 57 | |
---|
[d01564c] | 58 | #ifndef __rtems__ |
---|
[9054adf] | 59 | /* |
---|
| 60 | * This is declared to take a `void *' so that the caller is not required |
---|
| 61 | * to include <stdio.h> first. However, it is really a `FILE *', and the |
---|
| 62 | * manual page documents it as such. |
---|
| 63 | */ |
---|
| 64 | void |
---|
| 65 | err_set_file(void *fp) |
---|
| 66 | { |
---|
| 67 | if (fp) |
---|
| 68 | err_file = fp; |
---|
| 69 | else |
---|
| 70 | err_file = stderr; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void |
---|
| 74 | err_set_exit(void (*ef)(int)) |
---|
| 75 | { |
---|
| 76 | err_exit = ef; |
---|
| 77 | } |
---|
[d01564c] | 78 | #endif /* __rtems__ */ |
---|
[9054adf] | 79 | |
---|
| 80 | __weak_reference(_err, err); |
---|
| 81 | |
---|
| 82 | void |
---|
| 83 | _err(int eval, const char *fmt, ...) |
---|
| 84 | { |
---|
| 85 | va_list ap; |
---|
| 86 | va_start(ap, fmt); |
---|
| 87 | verrc(eval, errno, fmt, ap); |
---|
| 88 | va_end(ap); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void |
---|
| 92 | verr(eval, fmt, ap) |
---|
| 93 | int eval; |
---|
| 94 | const char *fmt; |
---|
| 95 | va_list ap; |
---|
| 96 | { |
---|
| 97 | verrc(eval, errno, fmt, ap); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | void |
---|
| 101 | errc(int eval, int code, const char *fmt, ...) |
---|
| 102 | { |
---|
| 103 | va_list ap; |
---|
| 104 | va_start(ap, fmt); |
---|
| 105 | verrc(eval, code, fmt, ap); |
---|
| 106 | va_end(ap); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void |
---|
| 110 | verrc(int eval, int code, const char *fmt, va_list ap) |
---|
| 111 | { |
---|
| 112 | if (err_file == 0) |
---|
| 113 | err_set_file((FILE *)0); |
---|
| 114 | fprintf(err_file, "%s: ", _getprogname()); |
---|
| 115 | if (fmt != NULL) { |
---|
| 116 | vfprintf(err_file, fmt, ap); |
---|
| 117 | fprintf(err_file, ": "); |
---|
| 118 | } |
---|
| 119 | fprintf(err_file, "%s\n", strerror(code)); |
---|
[d01564c] | 120 | #ifndef __rtems__ |
---|
[9054adf] | 121 | if (err_exit) |
---|
| 122 | err_exit(eval); |
---|
[d01564c] | 123 | #endif /* __rtems__ */ |
---|
[9054adf] | 124 | exit(eval); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | void |
---|
| 128 | errx(int eval, const char *fmt, ...) |
---|
| 129 | { |
---|
| 130 | va_list ap; |
---|
| 131 | va_start(ap, fmt); |
---|
| 132 | verrx(eval, fmt, ap); |
---|
| 133 | va_end(ap); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | void |
---|
| 137 | verrx(int eval, const char *fmt, va_list ap) |
---|
| 138 | { |
---|
| 139 | if (err_file == 0) |
---|
| 140 | err_set_file((FILE *)0); |
---|
| 141 | fprintf(err_file, "%s: ", _getprogname()); |
---|
| 142 | if (fmt != NULL) |
---|
| 143 | vfprintf(err_file, fmt, ap); |
---|
| 144 | fprintf(err_file, "\n"); |
---|
[d01564c] | 145 | #ifndef __rtems__ |
---|
[9054adf] | 146 | if (err_exit) |
---|
| 147 | err_exit(eval); |
---|
[d01564c] | 148 | #endif /* __rtems__ */ |
---|
[9054adf] | 149 | exit(eval); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | __weak_reference(_warn, warn); |
---|
| 153 | |
---|
| 154 | void |
---|
| 155 | _warn(const char *fmt, ...) |
---|
| 156 | { |
---|
| 157 | va_list ap; |
---|
| 158 | va_start(ap, fmt); |
---|
| 159 | vwarnc(errno, fmt, ap); |
---|
| 160 | va_end(ap); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void |
---|
| 164 | vwarn(const char *fmt, va_list ap) |
---|
| 165 | { |
---|
| 166 | vwarnc(errno, fmt, ap); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void |
---|
| 170 | warnc(int code, const char *fmt, ...) |
---|
| 171 | { |
---|
| 172 | va_list ap; |
---|
| 173 | va_start(ap, fmt); |
---|
| 174 | vwarnc(code, fmt, ap); |
---|
| 175 | va_end(ap); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | void |
---|
| 179 | vwarnc(int code, const char *fmt, va_list ap) |
---|
| 180 | { |
---|
| 181 | if (err_file == 0) |
---|
| 182 | err_set_file((FILE *)0); |
---|
| 183 | fprintf(err_file, "%s: ", _getprogname()); |
---|
| 184 | if (fmt != NULL) { |
---|
| 185 | vfprintf(err_file, fmt, ap); |
---|
| 186 | fprintf(err_file, ": "); |
---|
| 187 | } |
---|
| 188 | fprintf(err_file, "%s\n", strerror(code)); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | void |
---|
| 192 | warnx(const char *fmt, ...) |
---|
| 193 | { |
---|
| 194 | va_list ap; |
---|
| 195 | va_start(ap, fmt); |
---|
| 196 | vwarnx(fmt, ap); |
---|
| 197 | va_end(ap); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | void |
---|
| 201 | vwarnx(const char *fmt, va_list ap) |
---|
| 202 | { |
---|
| 203 | if (err_file == 0) |
---|
| 204 | err_set_file((FILE *)0); |
---|
| 205 | fprintf(err_file, "%s: ", _getprogname()); |
---|
| 206 | if (fmt != NULL) |
---|
| 207 | vfprintf(err_file, fmt, ap); |
---|
| 208 | fprintf(err_file, "\n"); |
---|
| 209 | } |
---|