maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
src
merror.h
Go to the documentation of this file.
1
2
#ifndef MERROR_H
3
#define MERROR_H
4
10
18
void
maug_critical_error
(
const
char
* msg );
19
24
28
typedef
uint16_t
MERROR_RETVAL
;
29
30
#define MERROR_OK 0x0000
31
38
#define MERROR_USR 0x0001
39
40
#define MERROR_OVERFLOW 0x0002
41
42
#define MERROR_FILE 0x0004
43
44
#define MERROR_ALLOC 0x0008
45
46
#define MERROR_PARSE 0x0010
47
48
#define MERROR_GUI 0x0020
49
50
#define MERROR_SND MERROR_GUI
51
52
#define MERROR_WAIT 0x0040
53
54
#define MERROR_EXEC MERROR_WAIT
55
56
#define MERROR_TIMEOUT 0x0080
57
63
67
#define MERROR_PREEMPT (MERROR_EXEC | MERROR_TIMEOUT)
68
73
#define MERROR_RESET (MERROR_EXEC | MERROR_PARSE)
74
/* maug_mlisp_retvals */
76
/* maug_error_retvals */
78
79
#define merror_sz_to_retval( sz ) ((sz) * -1)
80
81
#define merror_retval_to_sz( retval ) ((retval) * -1)
82
83
#define maug_cleanup_if_null_msg( type, ptr, err, msg ) \
84
if( (type)NULL == ptr ) { \
85
error_printf( msg ); \
86
retval = err; \
87
goto cleanup; \
88
}
89
90
#define maug_cleanup_if_not_null( type, ptr, err ) \
91
if( (type)NULL == ptr ) { \
92
error_printf( #ptr " is not NULL!" ); \
93
retval = err; \
94
goto cleanup; \
95
}
96
97
#define maug_cleanup_if_null( type, ptr, err ) \
98
maug_cleanup_if_null_msg( type, ptr, err, "failed to allocate " #ptr "!" )
99
100
#define maug_cleanup_if_null_alloc( type, ptr ) \
101
maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to allocate " #ptr "!" )
102
103
#define maug_cleanup_if_null_lock( type, ptr ) \
104
maug_cleanup_if_null_msg( type, ptr, MERROR_ALLOC, "failed to lock " #ptr "!" )
105
106
#define maug_cleanup_if_null_file( ptr ) \
107
maug_cleanup_if_null_msg( FILE*, ptr, MERROR_FILE, "failed to open FILE!" )
108
109
#define maug_cleanup_if_not_ok() \
110
if( MERROR_OK != retval ) { \
111
goto cleanup; \
112
}
113
114
#define maug_cleanup_if_not_ok_msg( msg ) \
115
if( MERROR_OK != retval ) { \
116
error_printf( msg ); \
117
goto cleanup; \
118
}
119
120
#define maug_cleanup_if_lt( a, b, fmt, err ) \
121
if( (a) < (b) ) { \
122
error_printf( fmt " is less than " fmt "!", a, b ); \
123
retval = err; \
124
goto cleanup; \
125
}
126
127
#define maug_cleanup_if_lt_overflow( a, b ) \
128
maug_cleanup_if_lt( a, b, SIZE_T_FMT, MERROR_OVERFLOW )
129
130
#define maug_cleanup_if_ge( a, b, fmt, err ) \
131
if( (a) >= (b) ) { \
132
error_printf( fmt " is greater or equal to " fmt "!", a, b ); \
133
retval = err; \
134
goto cleanup; \
135
}
136
137
#define maug_cleanup_if_ge_overflow( a, b ) \
138
maug_cleanup_if_ge( a, (size_t)(b), SIZE_T_FMT, MERROR_OVERFLOW )
139
140
#define maug_cleanup_if_eq( a, b, fmt, err ) \
141
if( (a) == (b) ) { \
142
error_printf( #a " " fmt " is equal to " #b " " fmt "!", a, b ); \
143
retval = err; \
144
goto cleanup; \
145
}
146
147
#define maug_cleanup_if_ne( a, b, fmt, err ) \
148
if( (a) != (b) ) { \
149
error_printf( #a " " fmt " is NOT equal to " #b " " fmt "!", a, b ); \
150
retval = err; \
151
goto cleanup; \
152
}
153
/* maug_error */
155
156
#endif
/* MERROR_H */
157
MERROR_RETVAL
uint16_t MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition
merror.h:28
maug_critical_error
void maug_critical_error(const char *msg)
Display an error dialog. This is a minimal function that can be called early on (e....
Generated by
1.13.2