diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-11 10:22:26 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-11 10:22:26 -0700 |
commit | ced8ab50af1429d9ba7651da1b3b78014fd76e79 (patch) | |
tree | 4f0975a2594c4bfa97ebaa6b263e712858d2e8a4 /libmisc/include | |
parent | d84daf84d2ced072782ef3c61e5088b06d950939 (diff) |
Diffstat (limited to 'libmisc/include')
-rw-r--r-- | libmisc/include/libmisc/assert.h | 24 | ||||
-rw-r--r-- | libmisc/include/libmisc/endian.h | 3 | ||||
-rw-r--r-- | libmisc/include/libmisc/vcall.h | 3 |
3 files changed, 28 insertions, 2 deletions
diff --git a/libmisc/include/libmisc/assert.h b/libmisc/include/libmisc/assert.h new file mode 100644 index 0000000..e7e0eb0 --- /dev/null +++ b/libmisc/include/libmisc/assert.h @@ -0,0 +1,24 @@ +/* libmisc/assert.h - More assertions + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBMISC_ASSERT_H_ +#define _LIBMISC_ASSERT_H_ + +#ifdef NDEBUG +# define assert_msg(expr, msg) ((void)0) +#else +# define assert_msg(expr, msg) do { if (!(expr)) __assert_msg_fail(#expr, __FILE__, __LINE__, __func__, msg); } while (0) +__attribute__((__noreturn__)) void +__assert_msg_fail(const char *expr, + const char *file, unsigned int line, const char *func, + const char *msg); +#endif + +#define assert(expr) assert_msg(expr, NULL) /* C89, POSIX-2001 */ +#define assert_notreached(msg) do { assert_msg(false, "not reached"); __builtin_unreachable(); } while (0) +#define static_assert _Static_assert /* C11 */ + +#endif /* _LIBMISC_ASSERT_H_ */ diff --git a/libmisc/include/libmisc/endian.h b/libmisc/include/libmisc/endian.h index 24d7d42..b1bc55c 100644 --- a/libmisc/include/libmisc/endian.h +++ b/libmisc/include/libmisc/endian.h @@ -7,9 +7,10 @@ #ifndef _LIBMISC_ENDIAN_H_ #define _LIBMISC_ENDIAN_H_ -#include <assert.h> #include <stdint.h> /* for uint{n}_t */ +#include <libmisc/assert.h> + /* Big endian *****************************************************************/ typedef struct { diff --git a/libmisc/include/libmisc/vcall.h b/libmisc/include/libmisc/vcall.h index ea9402e..9b54c06 100644 --- a/libmisc/include/libmisc/vcall.h +++ b/libmisc/include/libmisc/vcall.h @@ -7,9 +7,10 @@ #ifndef _LIBMISC_VCALL_H_ #define _LIBMISC_VCALL_H_ -#include <assert.h> /* for assert() and static_assert() */ #include <stddef.h> /* for offsetof() */ +#include <libmisc/assert.h> + #define VCALL(o, m, ...) \ ({ \ assert(o); \ |