Debian Codegraph @

usr/lib/common/aix/err.c

raw symbols SCIP
1 /*
2 * Implementation of the err/errx/verr/verrx/warn/warnx/vwarn/vwarnx
3 * functions from BSD.
4 *
5 * This file is public-domain; anyone may deal in it without restriction.
6 *
7 * Written by Graue <[email protected]> on January 16, 2006.
8 */
9 #if defined(__WIN32) || defined(_AIX)
10 #define NEED_ERR
11 #define LACK_PROGNAME
12 #define NEED_ENDIAN_STUBS
13 #define LACK_SYSTYPES
14 #endif
15
16 #ifdef NEED_ERR
17
18
19 /*
20 err/warn family of functions cheat sheet:
21
22 Print:
23 last component of program name
24 [ if fmt is non-NULL
25 ": "
26 the formatted error message
27 ]
28 [ if function name does not end in x
29 ": "
30 strerror(errno)
31 ]
32 newline
33
34 Then if function name has "err" in it, quit with exit code `eval'.
35
36 BSD's -x versions actually print ": " at the end if passed NULL, so I
37 duplicate that behavior. Passing these functions NULL is kind of useless
38 though.
39 */
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <stdarg.h>
44 #include <string.h>
45 #include <errno.h>
46
47 extern const char *__progname;
48 #define progname __progname
49
50 void vwarn(const char *fmt, va_list args)
51 {
52 fputs(progname, stderr);
53 if (fmt != NULL)
54 {
55 fputs(": ", stderr);
56 vfprintf(stderr, fmt, args);
57 }
58 fputs(": ", stderr);
59 fputs(strerror(errno), stderr);
60 putc('\n', stderr);
61 }
62
63 void vwarnx(const char *fmt, va_list args)
64 {
65 fputs(progname, stderr);
66 fputs(": ", stderr);
67 if (fmt != NULL)
68 vfprintf(stderr, fmt, args);
69 putc('\n', stderr);
70 }
71
72 void verr(int eval, const char *fmt, va_list args)
73 {
74 vwarn(fmt, args);
75 exit(eval);
76 }
77
78 void verrx(int eval, const char *fmt, va_list args)
79 {
80 vwarnx(fmt, args);
81 exit(eval);
82 }
83
84 void warn(const char *fmt, ...)
85 {
86 va_list argptr;
87 va_start(argptr, fmt);
88 vwarn(fmt, argptr);
89 va_end(argptr);
90 }
91
92 void warnx(const char *fmt, ...)
93 {
94 va_list argptr;
95 va_start(argptr, fmt);
96 vwarnx(fmt, argptr);
97 va_end(argptr);
98 }
99
100 void err(int eval, const char *fmt, ...)
101 {
102 va_list argptr;
103 va_start(argptr, fmt);
104 verr(eval, fmt, argptr);
105 /* NOTREACHED, so don't worry about va_end() */
106 }
107
108 void errx(int eval, const char *fmt, ...)
109 {
110 va_list argptr;
111 va_start(argptr, fmt);
112 verrx(eval, fmt, argptr);
113 /* NOTREACHED, so don't worry about va_end() */
114 }
115
116 #endif