source: rtems-libbsd/freebsd/lib/libc/gen/err.c @ f41a394

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since f41a394 was d48955b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/06/13 at 08:02:16

Add and use <machine/rtems-bsd-user-space.h>

  • Property mode set to 100644
File size: 4.6 KB
Line 
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)
33static 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__
50static FILE *err_file; /* file to use for error output */
51static void (*err_exit)(int);
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__ */
57
58#ifndef __rtems__
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 */
64void
65err_set_file(void *fp)
66{
67        if (fp)
68                err_file = fp;
69        else
70                err_file = stderr;
71}
72
73void
74err_set_exit(void (*ef)(int))
75{
76        err_exit = ef;
77}
78#endif /* __rtems__ */
79
80__weak_reference(_err, err);
81
82void
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
91void
92verr(eval, fmt, ap)
93        int eval;
94        const char *fmt;
95        va_list ap;
96{
97        verrc(eval, errno, fmt, ap);
98}
99
100void
101errc(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
109void
110verrc(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));
120#ifndef __rtems__
121        if (err_exit)
122                err_exit(eval);
123#endif /* __rtems__ */
124        exit(eval);
125}
126
127void
128errx(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
136void
137verrx(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");
145#ifndef __rtems__
146        if (err_exit)
147                err_exit(eval);
148#endif /* __rtems__ */
149        exit(eval);
150}
151
152__weak_reference(_warn, warn);
153
154void
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
163void
164vwarn(const char *fmt, va_list ap)
165{
166        vwarnc(errno, fmt, ap);
167}
168
169void
170warnc(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
178void
179vwarnc(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
191void
192warnx(const char *fmt, ...)
193{
194        va_list ap;
195        va_start(ap, fmt);
196        vwarnx(fmt, ap);
197        va_end(ap);
198}
199
200void
201vwarnx(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}
Note: See TracBrowser for help on using the repository browser.