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

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 21abaef was 21abaef, checked in by Christian Mauderer <Christian.Mauderer@…>, on Jul 15, 2016 at 5:32:56 AM

freebsd: Don't use new wrappers for old ports.

Some of the commands have been adapted manually. So the wrapper
currently don't necessarily work as expected. For example ifconfig calls
malloc outside of the program call.

  • Property mode set to 100644
File size: 5.0 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#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 */
73void
74err_set_file(void *fp)
75{
76        if (fp)
77                err_file = fp;
78        else
79                err_file = stderr;
80}
81
82void
83err_set_exit(void (*ef)(int))
84{
85        err_exit = ef;
86}
87#endif /* __rtems__ */
88
89__weak_reference(_err, err);
90
91void
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
100void
101verr(eval, fmt, ap)
102        int eval;
103        const char *fmt;
104        va_list ap;
105{
106        verrc(eval, errno, fmt, ap);
107}
108
109void
110errc(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
118void
119verrc(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
136void
137errx(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
145void
146verrx(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
163void
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
172void
173vwarn(const char *fmt, va_list ap)
174{
175        vwarnc(errno, fmt, ap);
176}
177
178void
179warnc(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
187void
188vwarnc(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
200void
201warnx(const char *fmt, ...)
202{
203        va_list ap;
204        va_start(ap, fmt);
205        vwarnx(fmt, ap);
206        va_end(ap);
207}
208
209void
210vwarnx(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}
Note: See TracBrowser for help on using the repository browser.