maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
merror.h
Go to the documentation of this file.
1
2#ifndef MERROR_H
3#define MERROR_H
4
19typedef int MERROR_RETVAL;
20
21#define MERROR_OK 0x0000
22
23#define MERROR_USR 0x0001
24
25#define MERROR_OVERFLOW 0x0002
26
27#define MERROR_FILE 0x0004
28
29#define MERROR_ALLOC 0x0008
30
31#define MERROR_PARSE 0x0010
32
33#define MERROR_GUI 0x0020
34
35#define MERROR_SND 0x0020
36
37#define MERROR_WAIT 0x0040
38
39#define MERROR_EXEC 0x0040
40
41/* MERROR_EXEC + MERROR_TIMEOUT */
42#define MERROR_PREEMPT 0x00c0
43
44#define MERROR_TIMEOUT 0x0080
45
46 /* maug_error_retvals */
47
48#define maug_cleanup_if_null_msg( type, ptr, err, msg ) \
49 if( (type)NULL == ptr ) { \
50 error_printf( msg ); \
51 retval = err; \
52 goto cleanup; \
53 }
54
55#define maug_cleanup_if_not_null( type, ptr, err ) \
56 if( (type)NULL == ptr ) { \
57 error_printf( #ptr " is not NULL!" ); \
58 retval = err; \
59 goto cleanup; \
60 }
61
62#define maug_cleanup_if_null( type, ptr, err ) \
63 maug_cleanup_if_null_msg( type, ptr, err, "failed to allocate " #ptr "!" )
64
65#define maug_cleanup_if_null_alloc( type, ptr ) \
66 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to allocate " #ptr "!" )
67
68#define maug_cleanup_if_null_lock( type, ptr ) \
69 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to lock " #ptr "!" )
70
71#define maug_cleanup_if_null_file( ptr ) \
72 maug_cleanup_if_null_msg( FILE*, ptr, MERROR_FILE, "failed to open FILE!" )
73
74#define maug_cleanup_if_not_ok() \
75 if( MERROR_OK != retval ) { \
76 goto cleanup; \
77 }
78
79#define maug_cleanup_if_lt( a, b, fmt, err ) \
80 if( (a) < (b) ) { \
81 error_printf( fmt " is less than " fmt "!", a, b ); \
82 retval = err; \
83 goto cleanup; \
84 }
85
86#define maug_cleanup_if_lt_overflow( a, b ) \
87 maug_cleanup_if_lt( a, b, SIZE_T_FMT, MERROR_OVERFLOW )
88
89#define maug_cleanup_if_ge( a, b, fmt, err ) \
90 if( (a) >= (b) ) { \
91 error_printf( fmt " is greater or equal to " fmt "!", a, b ); \
92 retval = err; \
93 goto cleanup; \
94 }
95
96#define maug_cleanup_if_ge_overflow( a, b ) \
97 maug_cleanup_if_ge( a, (size_t)(b), SIZE_T_FMT, MERROR_OVERFLOW )
98
99 /* maug_error */
100
101#endif /* MERROR_H */
102
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19