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
10
15
19typedef int MERROR_RETVAL;
20
21#define MERROR_OK 0x0000
22
29#define MERROR_USR 0x0001
30
31#define MERROR_OVERFLOW 0x0002
32
33#define MERROR_FILE 0x0004
34
35#define MERROR_ALLOC 0x0008
36
37#define MERROR_PARSE 0x0010
38
39#define MERROR_GUI 0x0020
40
41#define MERROR_SND MERROR_GUI
42
43#define MERROR_WAIT 0x0040
44
45#define MERROR_EXEC MERROR_WAIT
46
47#define MERROR_TIMEOUT 0x0080
48
54
58#define MERROR_PREEMPT (MERROR_EXEC | MERROR_TIMEOUT)
59
64#define MERROR_RESET (MERROR_EXEC | MERROR_PARSE)
65 /* maug_mlisp_retvals */
67 /* maug_error_retvals */
69
70#define merror_sz_to_retval( sz ) ((sz) * -1)
71
72#define merror_retval_to_sz( retval ) ((retval) * -1)
73
74#define maug_cleanup_if_null_msg( type, ptr, err, msg ) \
75 if( (type)NULL == ptr ) { \
76 error_printf( msg ); \
77 retval = err; \
78 goto cleanup; \
79 }
80
81#define maug_cleanup_if_not_null( type, ptr, err ) \
82 if( (type)NULL == ptr ) { \
83 error_printf( #ptr " is not NULL!" ); \
84 retval = err; \
85 goto cleanup; \
86 }
87
88#define maug_cleanup_if_null( type, ptr, err ) \
89 maug_cleanup_if_null_msg( type, ptr, err, "failed to allocate " #ptr "!" )
90
91#define maug_cleanup_if_null_alloc( type, ptr ) \
92 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to allocate " #ptr "!" )
93
94#define maug_cleanup_if_null_lock( type, ptr ) \
95 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to lock " #ptr "!" )
96
97#define maug_cleanup_if_null_file( ptr ) \
98 maug_cleanup_if_null_msg( FILE*, ptr, MERROR_FILE, "failed to open FILE!" )
99
100#define maug_cleanup_if_not_ok() \
101 if( MERROR_OK != retval ) { \
102 goto cleanup; \
103 }
104
105#define maug_cleanup_if_not_ok_msg( msg ) \
106 if( MERROR_OK != retval ) { \
107 error_printf( msg ); \
108 goto cleanup; \
109 }
110
111#define maug_cleanup_if_lt( a, b, fmt, err ) \
112 if( (a) < (b) ) { \
113 error_printf( fmt " is less than " fmt "!", a, b ); \
114 retval = err; \
115 goto cleanup; \
116 }
117
118#define maug_cleanup_if_lt_overflow( a, b ) \
119 maug_cleanup_if_lt( a, b, SIZE_T_FMT, MERROR_OVERFLOW )
120
121#define maug_cleanup_if_ge( a, b, fmt, err ) \
122 if( (a) >= (b) ) { \
123 error_printf( fmt " is greater or equal to " fmt "!", a, b ); \
124 retval = err; \
125 goto cleanup; \
126 }
127
128#define maug_cleanup_if_ge_overflow( a, b ) \
129 maug_cleanup_if_ge( a, (size_t)(b), SIZE_T_FMT, MERROR_OVERFLOW )
130
131#define maug_cleanup_if_eq( a, b, fmt, err ) \
132 if( (a) == (b) ) { \
133 error_printf( #a " " fmt " is equal to " #b " " fmt "!", a, b ); \
134 retval = err; \
135 goto cleanup; \
136 }
137
138#define maug_cleanup_if_ne( a, b, fmt, err ) \
139 if( (a) != (b) ) { \
140 error_printf( #a " " fmt " is NOT equal to " #b " " fmt "!", a, b ); \
141 retval = err; \
142 goto cleanup; \
143 }
144 /* maug_error */
146
147#endif /* MERROR_H */
148
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19