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 0x0020
42
43#define MERROR_WAIT 0x0040
44
45#define MERROR_EXEC 0x0040
46
47/* MERROR_EXEC + MERROR_TIMEOUT */
48#define MERROR_PREEMPT 0x00c0
49
50#define MERROR_TIMEOUT 0x0080
51 /* maug_error_retvals */
53
54#define merror_sz_to_retval( sz ) ((sz) * -1)
55
56#define merror_retval_to_sz( retval ) ((retval) * -1)
57
58#define maug_cleanup_if_null_msg( type, ptr, err, msg ) \
59 if( (type)NULL == ptr ) { \
60 error_printf( msg ); \
61 retval = err; \
62 goto cleanup; \
63 }
64
65#define maug_cleanup_if_not_null( type, ptr, err ) \
66 if( (type)NULL == ptr ) { \
67 error_printf( #ptr " is not NULL!" ); \
68 retval = err; \
69 goto cleanup; \
70 }
71
72#define maug_cleanup_if_null( type, ptr, err ) \
73 maug_cleanup_if_null_msg( type, ptr, err, "failed to allocate " #ptr "!" )
74
75#define maug_cleanup_if_null_alloc( type, ptr ) \
76 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to allocate " #ptr "!" )
77
78#define maug_cleanup_if_null_lock( type, ptr ) \
79 maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to lock " #ptr "!" )
80
81#define maug_cleanup_if_null_file( ptr ) \
82 maug_cleanup_if_null_msg( FILE*, ptr, MERROR_FILE, "failed to open FILE!" )
83
84#define maug_cleanup_if_not_ok() \
85 if( MERROR_OK != retval ) { \
86 goto cleanup; \
87 }
88
89#define maug_cleanup_if_not_ok_msg( msg ) \
90 if( MERROR_OK != retval ) { \
91 error_printf( msg ); \
92 goto cleanup; \
93 }
94
95#define maug_cleanup_if_lt( a, b, fmt, err ) \
96 if( (a) < (b) ) { \
97 error_printf( fmt " is less than " fmt "!", a, b ); \
98 retval = err; \
99 goto cleanup; \
100 }
101
102#define maug_cleanup_if_lt_overflow( a, b ) \
103 maug_cleanup_if_lt( a, b, SIZE_T_FMT, MERROR_OVERFLOW )
104
105#define maug_cleanup_if_ge( a, b, fmt, err ) \
106 if( (a) >= (b) ) { \
107 error_printf( fmt " is greater or equal to " fmt "!", a, b ); \
108 retval = err; \
109 goto cleanup; \
110 }
111
112#define maug_cleanup_if_ge_overflow( a, b ) \
113 maug_cleanup_if_ge( a, (size_t)(b), SIZE_T_FMT, MERROR_OVERFLOW )
114
115#define maug_cleanup_if_eq( a, b, fmt, err ) \
116 if( (a) == (b) ) { \
117 error_printf( #a " " fmt " is equal to " #b " " fmt "!", a, b ); \
118 retval = err; \
119 goto cleanup; \
120 }
121
122#define maug_cleanup_if_ne( a, b, fmt, err ) \
123 if( (a) != (b) ) { \
124 error_printf( #a " " fmt " is NOT equal to " #b " " fmt "!", a, b ); \
125 retval = err; \
126 goto cleanup; \
127 }
128 /* maug_error */
130
131#endif /* MERROR_H */
132
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19