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_lt( a, b, fmt, err ) \
90 if( (a) < (b) ) { \
91 error_printf( fmt " is less than " fmt "!", a, b ); \
92 retval = err; \
93 goto cleanup; \
94 }
95
96#define maug_cleanup_if_lt_overflow( a, b ) \
97 maug_cleanup_if_lt( a, b, SIZE_T_FMT, MERROR_OVERFLOW )
98
99#define maug_cleanup_if_ge( a, b, fmt, err ) \
100 if( (a) >= (b) ) { \
101 error_printf( fmt " is greater or equal to " fmt "!", a, b ); \
102 retval = err; \
103 goto cleanup; \
104 }
105
106#define maug_cleanup_if_ge_overflow( a, b ) \
107 maug_cleanup_if_ge( a, (size_t)(b), SIZE_T_FMT, MERROR_OVERFLOW )
108 /* maug_error */
110
111#endif /* MERROR_H */
112
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19