diff options
| author | Federico Angelilli <code@fedang.net> | 2024-05-19 15:24:39 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-05-19 15:24:39 +0200 |
| commit | 0f9981cf5a15de92d24a2ff1580b6e832cbd5cb1 (patch) | |
| tree | f4967812fbc4b39713850012068c775a65df9e44 /any_check.h | |
| parent | af0de70502d4b5bd8e18cd2b7b4b732c17610844 (diff) | |
Add any_check.h
Diffstat (limited to 'any_check.h')
| -rw-r--r-- | any_check.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/any_check.h b/any_check.h new file mode 100644 index 0000000..5fdc268 --- /dev/null +++ b/any_check.h @@ -0,0 +1,37 @@ +#ifndef ANY_CHECK_INCLUDE +#define ANY_CHECK_INCLUDE + +#ifndef ANY_CHECK_PANIC +#ifdef log_panic +#define ANY_CHECK_PANIC log_panic +#else +#endif +#include <stdlib.h> +#include <stdio.h> +#define ANY_CHECK_PANIC(pred, ...) \ + do { \ + fprintf(stderr, "Check failed at %s:%d: %s\n", __FILE__, __LINE__, pred); \ + abort(); \ + } while (0) +#endif + +#define ANY_CHECK_STRING(...) # __VA_ARGS__ + +#define check_or(pred, ...) \ + do { \ + if (!(pred)) { \ + __VA_ARGS__ ; \ + } \ + } while (0) + +#define check_panic(pred, ...) check_or(pred, ANY_CHECK_PANIC(ANY_CHECK_STRING(pred), __VA_ARGS__) + +#ifdef ANY_CHECK_DEBUG +#define check_debug_or check_or +#define check_debug_panic check_panic +#else +#define check_debug_or(...) +#define check_debug_panic(...) +#endif + +#endif |
