vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / error.c
blob9bd3d91f642b5af07efc337f7e421f3a94e52482
1 /* -*- c-basic-offset: 8; -*- */
2 #include <errno.h> /* for definition of errno */
3 #include <stdarg.h> /* ANSI C header file */
4 #include "ourhdr.h"
6 static void err_doit(int, const char *, va_list);
8 char *pname = NULL; /* caller can set this from argv[0] */
10 /* Nonfatal error related to a system call.
11 * Print a message and return. */
13 void
14 /* $f err_ret $ */
15 err_ret(const char *fmt, ...)
17 va_list ap;
19 va_start(ap, fmt);
20 err_doit(1, fmt, ap);
21 va_end(ap);
22 return;
25 /* Fatal error related to a system call.
26 * Print a message and terminate. */
28 void
29 /* $f err_sys $ */
30 err_sys(const char *fmt, ...)
32 va_list ap;
34 va_start(ap, fmt);
35 err_doit(1, fmt, ap);
36 va_end(ap);
37 exit(1);
40 /* Fatal error related to a system call.
41 * Print a message, dump core, and terminate. */
43 void
44 /* $f err_dump $ */
45 err_dump(const char *fmt, ...)
47 va_list ap;
49 va_start(ap, fmt);
50 err_doit(1, fmt, ap);
51 va_end(ap);
52 abort(); /* dump core and terminate */
53 exit(1); /* shouldn't get here */
56 /* Nonfatal error unrelated to a system call.
57 * Print a message and return. */
59 void
60 /* $f err_msg $ */
61 err_msg(const char *fmt, ...)
63 va_list ap;
65 va_start(ap, fmt);
66 err_doit(0, fmt, ap);
67 va_end(ap);
68 return;
71 /* Fatal error unrelated to a system call.
72 * Print a message and terminate. */
74 void
75 /* $f err_quit $ */
76 err_quit(const char *fmt, ...)
78 va_list ap;
80 va_start(ap, fmt);
81 err_doit(0, fmt, ap);
82 va_end(ap);
83 exit(1);
86 /* Print a message and return to caller.
87 * Caller specifies "errnoflag". */
89 static void
90 err_doit(int errnoflag, const char *fmt, va_list ap)
92 int errno_save;
93 char buf[MAXLINE];
95 errno_save = errno; /* value caller might want printed */
96 vsprintf(buf, fmt, ap);
97 if (errnoflag)
98 sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
99 strcat(buf, "\n");
100 fflush(stdout); /* in case stdout and stderr are the same */
101 fputs(buf, stderr);
102 fflush(stderr); /* SunOS 4.1.* doesn't grok NULL argument */
103 return;