1 /* $Id: e_err.h,v 1.12 2000/05/14 14:39:39 jens Exp $ */
2 /*
3  * Copyright (c) 1999, 2000
4  *      Jens A. Nilsson, jnilsson@ludd.luth.se. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef E_ERR__H
29 #define E_ERR__H
30 
31 #include <stdarg.h>
32 #include <stdio.h>
33 
34 #ifdef MEMDEBUG
35 #include <memdebug.h>
36 #endif
37 
38 /* drop in replacement for err.h */
39 #define	err		e_err
40 #define	errx	e_errx
41 #define	warn	e_warn
42 #define	warnx	e_warnx
43 
44 /* default is progname = __progname and file = stderr */
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 void e_set_progname(char *name);
51 const char *e_get_progname(void);
52 
53 void e_set_log_facil(int facility);
54 int e_get_log_facil(void);
55 void e_set_log_prio(int prio);
56 int e_get_log_prio(void);
57 void e_use_log(void);
58 
59 void e_set_file(FILE *fp);
60 FILE *e_get_file(void);
61 void e_use_file(void);
62 
63 void e_set_level(int level);
64 int e_get_level(void);
65 
66 void e_set_section(int section);
67 int e_get_section(void);
68 
69 void e_set_newline_str(const char *str);
70 const char *e_get_newline_str(void);
71 
72 void e_buf_log(char *buf, int prio);
73 void e_buf_file(char *buf, FILE *fp);
74 void e_buf_format(char *buf, size_t len,
75 	const char *name, char *error, const char *fmt, va_list args);
76 
77 /* does e_use_log and the daemon(3) */
78 int e_daemon(int nochdir, int noclose, int facility, int prio);
79 
80 /* suitable to use as a complement to usage() on error */
81 void e_usage(const char *fmt, ...)
82 	__attribute__ ((format (printf, 1, 2)));
83 
84 /* exit with eval and print error mesage with strerror(errno)
85  * appended to message.  */
86 void e_verr(int eval, const char *fmt, va_list args);
87 void e_err(int eval, const char *fmt, ...)
88 	__attribute__ ((format (printf, 2, 3)));
89 
90 void e_verr_log(int eval, int prio, const char *fmt, va_list args);
91 void e_err_log(int eval, int prio, const char *fmt, ...)
92 	__attribute__ ((format (printf, 3, 4)));
93 
94 void e_verr_file(int eval, FILE *fp, const char *fmt, va_list args);
95 void e_err_file(int eval, FILE *fp, const char *fmt, ...)
96 	__attribute__ ((format (printf, 3, 4)));
97 
98 /* exit with eval and print error mesage */
99 void e_verrx(int eval, const char *fmt, va_list args);
100 void e_errx(int eval, const char *fmt, ...)
101 	__attribute__ ((format (printf, 2, 3)));
102 
103 void e_verrx_log(int eval, int prio, const char *fmt, va_list args);
104 void e_errx_log(int eval, int prio, const char *fmt, ...)
105 	__attribute__ ((format (printf, 3, 4)));
106 
107 void e_verrx_file(int eval, FILE *fp, const char *fmt, va_list args);
108 void e_errx_file(int eval, FILE *fp, const char *fmt, ...)
109 	__attribute__ ((format (printf, 3, 4)));
110 
111 /* print error mesage with strerror(errno) appended to message.  */
112 void e_vtrace(int level, int section, const char *fmt, va_list args);
113 void e_trace(int level, int section, const char *fmt, ...)
114 	__attribute__ ((format (printf, 3, 4)));
115 
116 void e_vtrace_log(int level, int section, int prio,
117 	const char *fmt, va_list args);
118 void e_trace_log(int level, int section, int prio, const char *fmt, ...)
119 	__attribute__ ((format (printf, 4, 5)));
120 
121 void e_vtrace_file(int level, int section, FILE *fp,
122 	const char *fmt, va_list args);
123 void e_trace_file(int level, int section, FILE *fp, const char *fmt, ...)
124 	__attribute__ ((format (printf, 4, 5)));
125 
126 void e_vlog(int level, const char *fmt, va_list args);
127 void e_log(int level, const char *fmt, ...)
128 	__attribute__ ((format (printf, 2, 3)));
129 
130 void e_vlog_log(int level, int prio, const char *fmt, va_list args);
131 void e_log_log(int level, int prio, const char *fmt, ...)
132 	__attribute__ ((format (printf, 3, 4)));
133 
134 void e_vlog_file(int level, FILE *fp, const char *fmt, va_list args);
135 void e_log_file(int level, FILE *fp, const char *fmt, ...)
136 	__attribute__ ((format (printf, 3, 4)));
137 
138 void e_vwarn(const char *fmt, va_list args);
139 void e_warn(const char *fmt, ...)
140 	__attribute__ ((format (printf, 1, 2)));
141 
142 void e_vwarn_log(int prio, const char *fmt, va_list args);
143 void e_warn_log(int prio, const char *fmt, ...)
144 	__attribute__ ((format (printf, 2, 3)));
145 
146 void e_vwarn_file(FILE *fp, const char *fmt, va_list args);
147 void e_warn_file(FILE *fp, const char *fmt, ...)
148 	__attribute__ ((format (printf, 2, 3)));
149 
150 /* print error mesage */
151 void e_vtracex(int level, int section, const char *fmt, va_list args);
152 void e_tracex(int level, int section, const char *fmt, ...)
153 	__attribute__ ((format (printf, 3, 4)));
154 
155 void e_vtracex_log(int level, int section, int prio,
156 	const char *fmt, va_list args);
157 void e_tracex_log(int level, int section, int prio, const char *fmt, ...)
158 	__attribute__ ((format (printf, 4, 5)));
159 
160 void e_vtracex_file(int level, int section, FILE *fp,
161 	const char *fmt, va_list args);
162 void e_tracex_file(int level, int section, FILE *fp, const char *fmt, ...)
163 	__attribute__ ((format (printf, 4, 5)));
164 
165 void e_vlogx(int level, const char *fmt, va_list args);
166 void e_logx(int level, const char *fmt, ...)
167 	__attribute__ ((format (printf, 2, 3)));
168 
169 void e_vlogx_log(int level, int prio, const char *fmt, va_list args);
170 void e_logx_log(int level, int prio, const char *fmt, ...)
171 	__attribute__ ((format (printf, 3, 4)));
172 
173 void e_vlogx_file(int level, FILE *fp, const char *fmt, va_list args);
174 void e_logx_file(int level, FILE *fp, const char *fmt, ...)
175 	__attribute__ ((format (printf, 3, 4)));
176 
177 void e_vwarnx(const char *fmt, va_list args);
178 void e_warnx(const char *fmt, ...)
179 	__attribute__ ((format (printf, 1, 2)));
180 
181 void e_vwarnx_log(int prio, const char *fmt, va_list args);
182 void e_warnx_log(int prio, const char *fmt, ...)
183 	__attribute__ ((format (printf, 2, 3)));
184 
185 void e_vwarnx_file(FILE *fp, const char *fmt, va_list args);
186 void e_warnx_file(FILE *fp, const char *fmt, ...)
187 	__attribute__ ((format (printf, 2, 3)));
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* E_ERR__H */
194