Skip to content

Commit 9c7c3a5

Browse files
committed
Add macro for checking a condition and returning
and printing information regarding the failure. It's useful for checking arguments as there are a lot of possible error conditions and we only have a single INVALID_ARGUMENT status.
1 parent 75cfd39 commit 9c7c3a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/utils/utils_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef UMF_COMMON_H
1111
#define UMF_COMMON_H 1
1212

13+
#include <stdio.h>
1314
#include <stdlib.h>
1415
#include <string.h>
1516

@@ -67,6 +68,15 @@ static inline void *Zalloc(size_t s) {
6768
} while (0)
6869
#endif
6970

71+
#define UMF_CHECK(condition, errorStatus) \
72+
do { \
73+
if (!(condition)) { \
74+
fprintf(stderr, "UMF check failed: " #condition " in %s\n", \
75+
__func__); \
76+
return errorStatus; \
77+
} \
78+
} while (0)
79+
7080
#ifdef __cplusplus
7181
}
7282
#endif

0 commit comments

Comments
 (0)