1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/include/kernaux/assert.h

40 lines
1.3 KiB
C
Raw Normal View History

2021-12-14 15:37:11 -05:00
#ifndef KERNAUX_INCLUDED_ASSERT
2021-12-20 01:17:53 -05:00
#define KERNAUX_INCLUDED_ASSERT
2021-12-14 15:37:11 -05:00
#ifdef __cplusplus
extern "C" {
#endif
2021-12-17 18:43:19 -05:00
#ifdef KERNAUX_ENABLE_ASSERT
#define KERNAUX_ASSERT(cond) \
((cond) ? (void)0 : kernaux_assert_do(__FILE__, __LINE__, #cond))
2021-12-17 18:43:19 -05:00
#else
#define KERNAUX_ASSERT(cond) ((void)sizeof((cond)))
#endif
2021-12-19 21:22:43 -05:00
#if defined(KERNAUX_ENABLE_GUARD) || defined(KERNAUX_ENABLE_GUARD_COND)
#define KERNAUX_ASSERT_RETURN(cond) { KERNAUX_ASSERT(cond); if (!(cond)) return; }
#define KERNAUX_ASSERT_RETVAL(cond, val) { KERNAUX_ASSERT(cond); if (!(cond)) return (val); }
#else
#define KERNAUX_ASSERT_RETURN(cond) { KERNAUX_ASSERT(cond); }
#define KERNAUX_ASSERT_RETVAL(cond, val) { KERNAUX_ASSERT(cond); }
#endif
#if defined(KERNAUX_ENABLE_GUARD) || defined(KERNAUX_ENABLE_GUARD_NULL)
#define KERNAUX_NOTNULL_RETURN(cond) { KERNAUX_ASSERT(cond); if (!(cond)) return; }
#define KERNAUX_NOTNULL_RETVAL(cond, val) { KERNAUX_ASSERT(cond); if (!(cond)) return (val); }
2021-12-17 18:43:19 -05:00
#else
#define KERNAUX_NOTNULL_RETURN(cond) { KERNAUX_ASSERT(cond); }
#define KERNAUX_NOTNULL_RETVAL(cond, val) { KERNAUX_ASSERT(cond); }
#endif
2021-12-14 15:37:11 -05:00
void kernaux_assert_do(const char *file, int line, const char *str);
extern void (*kernaux_assert_cb)(const char *file, int line, const char *str);
#ifdef __cplusplus
}
#endif
#endif