1
|
1 |
|
|
2 |
/*
|
|
3 |
* error handling
|
|
4 |
*/
|
|
5 |
|
|
6 |
void _generic_err ( /*int level, */ int use_stderr, const char *func, int perr, const char *fmt, ...)
|
|
7 |
__attribute__ ((format (printf, 4, 5)));
|
|
8 |
|
|
9 |
// needs to be defined as its own function for the noreturn attribute
|
|
10 |
void _generic_err_exit ( /* int level, */ int used_stderr, const char *func, int perr, const char *fmt, ...)
|
|
11 |
__attribute__ ((format (printf, 4, 5)))
|
|
12 |
__attribute__ ((noreturn));
|
|
13 |
|
|
14 |
enum _debug_level {
|
|
15 |
DEBUG_FATAL,
|
|
16 |
DEBUG_ERROR,
|
|
17 |
DEBUG_WARNING,
|
|
18 |
DEBUG_INFO,
|
|
19 |
DEBUG_DEBUG,
|
|
20 |
};
|
|
21 |
|
|
22 |
// not currently used
|
|
23 |
extern enum _debug_level _cur_debug_level;
|
|
24 |
|
|
25 |
// various kinds of ways to handle an error, 2**3 of them, *g*
|
|
26 |
#define info(...) _generic_err( 0, NULL, 0, __VA_ARGS__ )
|
|
27 |
#define error(...) _generic_err( 1, NULL, 0, __VA_ARGS__ )
|
|
28 |
#define err_exit(...) _generic_err_exit( 1, NULL, 0, __VA_ARGS__ )
|
|
29 |
#define perr(...) _generic_err( 1, NULL, 1, __VA_ARGS__ )
|
|
30 |
#define perr_exit(...) _generic_err_exit( 1, NULL, 1, __VA_ARGS__ )
|
|
31 |
#define err_func(func, ...) _generic_err( 1, func, 0, __VA_ARGS__ )
|
|
32 |
#define err_func_exit(func, ...) _generic_err_exit( 1, func, 0, __VA_ARGS__ )
|
|
33 |
#define perr_func(func, ...) _generic_err( 1, func, 1, __VA_ARGS__ )
|
|
34 |
#define perr_func_exit(func, ...) _generic_err_exit( 1, func, 1, __VA_ARGS__ )
|
2
|
35 |
#define eerr_func(func, err, ...) _generic_err( 1, func, err,__VA_ARGS__ )
|
1
|
36 |
|
2
|
37 |
/*
|
|
38 |
* error(func + colon + msg, ...) + goto error
|
|
39 |
* err = negative error code
|
|
40 |
*/
|
1
|
41 |
#define ERROR(...) do { err_func(__func__, __VA_ARGS__); goto error; } while (0)
|
|
42 |
#define PERROR(...) do { perr_func(__func__, __VA_ARGS__); goto error; } while (0)
|
2
|
43 |
#define EERROR(err, ...) do { eerr_func(__func__, (err), __VA_ARGS__); goto error; } while (0)
|
1
|
44 |
#define FATAL(...) err_func_exit(__func__, __VA_ARGS__)
|
|
45 |
#define PFATAL(...) perr_func_exit(__func__, __VA_ARGS__)
|
|
46 |
#define WARNING(...) err_func(__func__, __VA_ARGS__)
|
|
47 |
#define PWARNING(...) perr_func(__func__, __VA_ARGS__)
|
2
|
48 |
#define EWARNING(err, ...) eerr_func(__func__, (err), __VA_ARGS__)
|
1
|
49 |
|
|
50 |
#ifdef DEBUG_ENABLED
|
|
51 |
#define DEBUG(...) err_func(__func__, __VA_ARGS__)
|
|
52 |
#else
|
|
53 |
#define DEBUG(...) (void) (0)
|
|
54 |
#endif
|
|
55 |
|
|
56 |
// default is to enable INFO
|
|
57 |
#ifdef INFO_DISABLED
|
|
58 |
#define INFO_ENABLED 0
|
|
59 |
#else
|
|
60 |
#ifndef INFO_ENABLED
|
|
61 |
#define INFO_ENABLED 1
|
|
62 |
#endif
|
|
63 |
#endif
|
|
64 |
|
|
65 |
#if INFO_ENABLED
|
|
66 |
#define INFO(...) info(__VA_ARGS__)
|
|
67 |
#else
|
|
68 |
#define INFO(...) (void) (0)
|
|
69 |
#endif
|
|
70 |
|