Mercurial > code
comparison port/err.c @ 114:bb2694382675
Move err.[ch] to port/ directory
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 13 Feb 2012 18:06:07 +0100 |
parents | err.c@b1a084c030c8 |
children |
comparison
equal
deleted
inserted
replaced
113:d3ccd7232e2d | 114:bb2694382675 |
---|---|
1 /* | |
2 * err.c -- formtted error messages (portable version) | |
3 * | |
4 * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <stdarg.h> | |
22 #include <string.h> | |
23 #include <errno.h> | |
24 | |
25 #include "err.h" | |
26 | |
27 /* | |
28 * These functions implements at least the same functions that can be found | |
29 * in the NetBSD err(3) man page without printing the programe name due to | |
30 * a portability issue. | |
31 */ | |
32 | |
33 void | |
34 err(int val, const char *fmt, ...) | |
35 { | |
36 va_list ap; | |
37 | |
38 va_start(ap, fmt); | |
39 verr(val, fmt, ap); | |
40 va_end(ap); | |
41 } | |
42 | |
43 void | |
44 verr(int val, const char *fmt, va_list ap) | |
45 { | |
46 if (fmt) { | |
47 vfprintf(stderr, fmt, ap); | |
48 fprintf(stderr, ": "); | |
49 } | |
50 | |
51 fprintf(stderr, "%s\n", strerror(errno)); | |
52 exit(val); | |
53 } | |
54 | |
55 void | |
56 errx(int val, const char *fmt, ...) | |
57 { | |
58 va_list ap; | |
59 | |
60 va_start(ap, fmt); | |
61 verrx(val, fmt, ap); | |
62 va_end(ap); | |
63 } | |
64 | |
65 void | |
66 verrx(int val, const char *fmt, va_list ap) | |
67 { | |
68 if (fmt) | |
69 vfprintf(stderr, fmt, ap); | |
70 | |
71 fprintf(stderr, "\n"); | |
72 | |
73 exit(val); | |
74 } | |
75 | |
76 void | |
77 warn(const char *fmt, ...) | |
78 { | |
79 va_list ap; | |
80 | |
81 va_start(ap, fmt); | |
82 vwarn(fmt, ap); | |
83 va_end(ap); | |
84 } | |
85 | |
86 void | |
87 vwarn(const char *fmt, va_list ap) | |
88 { | |
89 if (fmt) { | |
90 vfprintf(stderr, fmt, ap); | |
91 fprintf(stderr, ": "); | |
92 } | |
93 | |
94 fprintf(stderr, "%s\n", strerror(errno)); | |
95 } | |
96 | |
97 void | |
98 warnx(const char *fmt, ...) | |
99 { | |
100 va_list ap; | |
101 | |
102 va_start(ap, fmt); | |
103 vwarnx(fmt, ap); | |
104 va_end(ap); | |
105 } | |
106 | |
107 void | |
108 vwarnx(const char *fmt, va_list ap) | |
109 { | |
110 if (fmt) | |
111 vfprintf(stderr, fmt, ap); | |
112 | |
113 fprintf(stderr, "\n"); | |
114 } |