libc: Add assert()
This commit is contained in:
parent
8398b2e2e4
commit
d0d6557e99
24
libs/libc/include/assert.h
Normal file
24
libs/libc/include/assert.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _ASSERT_H
|
||||||
|
#define _ASSERT_H
|
||||||
|
|
||||||
|
#include <bits/macros.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#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
|
12
libs/libc/src/assert.cpp
Normal file
12
libs/libc/src/assert.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user