diff --git a/libs/libc/include/assert.h b/libs/libc/include/assert.h new file mode 100644 index 00000000..62b79daa --- /dev/null +++ b/libs/libc/include/assert.h @@ -0,0 +1,24 @@ +#ifndef _ASSERT_H +#define _ASSERT_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + __lc_noreturn bool __assertion_failed(const char* file, int line, const char* function, const char* expr); + +#ifdef __cplusplus +} +#endif + +#ifdef NDEBUG +#define assert(expr) (void)0 +#else +#define assert(expr) (bool)(expr) || __assertion_failed(__FILE__, __LINE__, __FUNCTION__, #expr) +#endif + +#endif \ No newline at end of file diff --git a/libs/libc/src/assert.cpp b/libs/libc/src/assert.cpp new file mode 100644 index 00000000..c0c64a1c --- /dev/null +++ b/libs/libc/src/assert.cpp @@ -0,0 +1,12 @@ +#include +#include +#include + +extern "C" +{ + __lc_noreturn bool __assertion_failed(const char* file, int line, const char* function, const char* expr) + { + fprintf(stderr, "%s:%d: %s: Assertion '%s' failed.", file, line, function, expr); + abort(); + } +} \ No newline at end of file