3 |
3 |
4 /* |
4 /* |
5 * error handling |
5 * error handling |
6 */ |
6 */ |
7 |
7 |
8 void _generic_err ( /*int level, */ int use_stderr, const char *func, int perr, const char *fmt, ...) |
8 enum log_display_flags { |
|
9 LOG_DISPLAY_STDOUT = 0x00, |
|
10 LOG_DISPLAY_STDERR = 0x01, |
|
11 |
|
12 LOG_DISPLAY_PERR = 0x02, |
|
13 |
|
14 LOG_DISPLAY_NONL = 0x04, |
|
15 }; |
|
16 |
|
17 |
|
18 void _generic_err (int flags, const char *func, int err, const char *fmt, ...) |
9 __attribute__ ((format (printf, 4, 5))); |
19 __attribute__ ((format (printf, 4, 5))); |
10 |
20 |
11 // needs to be defined as its own function for the noreturn attribute |
21 // needs to be defined as its own function for the noreturn attribute |
12 void _generic_err_exit ( /* int level, */ int used_stderr, const char *func, int perr, const char *fmt, ...) |
22 void _generic_err_exit (int flags, const char *func, int err, const char *fmt, ...) |
13 __attribute__ ((format (printf, 4, 5))) |
23 __attribute__ ((format (printf, 4, 5))) |
14 __attribute__ ((noreturn)); |
24 __attribute__ ((noreturn)); |
15 |
25 |
16 enum _debug_level { |
26 enum _debug_level { |
17 DEBUG_FATAL, |
27 DEBUG_FATAL, |
23 |
33 |
24 // not currently used |
34 // not currently used |
25 extern enum _debug_level _cur_debug_level; |
35 extern enum _debug_level _cur_debug_level; |
26 |
36 |
27 // various kinds of ways to handle an error, 2**3 of them, *g* |
37 // various kinds of ways to handle an error, 2**3 of them, *g* |
28 #define info(...) _generic_err( 0, NULL, 0, __VA_ARGS__ ) |
38 #define info(...) _generic_err( LOG_DISPLAY_STDOUT, NULL, 0, __VA_ARGS__ ) |
29 #define error(...) _generic_err( 1, NULL, 0, __VA_ARGS__ ) |
39 #define error(...) _generic_err( LOG_DISPLAY_STDERR, NULL, 0, __VA_ARGS__ ) |
30 #define err_exit(...) _generic_err_exit( 1, NULL, 0, __VA_ARGS__ ) |
40 #define err_exit(...) _generic_err_exit( LOG_DISPLAY_STDERR, NULL, 0, __VA_ARGS__ ) |
31 #define perr(...) _generic_err( 1, NULL, 1, __VA_ARGS__ ) |
41 #define perr(...) _generic_err( LOG_DISPLAY_STDERR | LOG_DISPLAY_PERR, NULL, 0, __VA_ARGS__ ) |
32 #define perr_exit(...) _generic_err_exit( 1, NULL, 1, __VA_ARGS__ ) |
42 #define perr_exit(...) _generic_err_exit( LOG_DISPLAY_STDERR | LOG_DISPLAY_PERR, NULL, 0, __VA_ARGS__ ) |
33 #define err_func(func, ...) _generic_err( 1, func, 0, __VA_ARGS__ ) |
43 #define err_func(func, ...) _generic_err( LOG_DISPLAY_STDERR, func, 0, __VA_ARGS__ ) |
34 #define err_func_exit(func, ...) _generic_err_exit( 1, func, 0, __VA_ARGS__ ) |
44 #define err_func_exit(func, ...) _generic_err_exit( LOG_DISPLAY_STDERR, func, 0, __VA_ARGS__ ) |
35 #define perr_func(func, ...) _generic_err( 1, func, 1, __VA_ARGS__ ) |
45 #define perr_func(func, ...) _generic_err( LOG_DISPLAY_STDERR | LOG_DISPLAY_PERR, func, 0, __VA_ARGS__ ) |
36 #define perr_func_exit(func, ...) _generic_err_exit( 1, func, 1, __VA_ARGS__ ) |
46 #define perr_func_exit(func, ...) _generic_err_exit( LOG_DISPLAY_STDERR | LOG_DISPLAY_PERR, func, 0, __VA_ARGS__ ) |
37 #define eerr_func(func, err, ...) _generic_err( 1, func, err,__VA_ARGS__ ) |
47 #define eerr_func(func, err, ...) _generic_err( LOG_DISPLAY_STDERR | LOG_DISPLAY_PERR, func, err, __VA_ARGS__ ) |
|
48 #define debug(func, ...) _generic_err( LOG_DISPLAY_STDERR, func, 0, __VA_ARGS__ ) |
|
49 #define debug_nonl(func, ...) _generic_err( LOG_DISPLAY_STDERR | LOG_DISPLAY_NONL, func, 0, __VA_ARGS__ ) |
38 |
50 |
39 /* |
51 // logging includes errors |
40 * Legacy... |
|
41 */ |
|
42 #include "error.h" |
52 #include "error.h" |
43 |
53 |
44 #define WARNING(...) err_func(__func__, __VA_ARGS__) |
54 #define WARNING(...) err_func(__func__, __VA_ARGS__) |
45 #define PWARNING(...) perr_func(__func__, __VA_ARGS__) |
55 #define PWARNING(...) perr_func(__func__, __VA_ARGS__) |
46 #define EWARNING(err, ...) eerr_func(__func__, (err), __VA_ARGS__) |
56 #define EWARNING(err, ...) eerr_func(__func__, (err), __VA_ARGS__) |
47 |
57 |
48 #ifdef DEBUG_ENABLED |
58 #ifdef DEBUG_ENABLED |
49 #define DEBUG(...) err_func(__func__, __VA_ARGS__) |
59 #define DEBUG(...) debug(__func__, __VA_ARGS__) |
|
60 #define DEBUGF(...) debug(NULL, __VA_ARGS__) |
|
61 #define DEBUGN(...) debug_nonl(__func__, __VA_ARGS__) |
|
62 #define DEBUGNF(...) debug_nonl(NULL, __VA_ARGS__) |
50 #else |
63 #else |
51 #define DEBUG(...) (void) (0) |
64 #define DEBUG(...) (void) (0) |
|
65 #define DEBUGF(...) (void) (0) |
|
66 #define DEBUGN(...) (void) (0) |
|
67 #define DEBUGNF(...) (void) (0) |
52 #endif |
68 #endif |
53 |
69 |
54 // default is to enable INFO |
70 // default is to enable INFO |
55 #ifdef INFO_DISABLED |
71 #ifdef INFO_DISABLED |
56 #define INFO_ENABLED 0 |
72 #define INFO_ENABLED 0 |