mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
assert: add a partial assert implementation (LDEPS)
This currently does not link because fprintf, stderr and abort are missing on most platforms. But the code is there.
This commit is contained in:
parent
97d52ff0b1
commit
676601b894
3 changed files with 39 additions and 0 deletions
|
@ -58,6 +58,7 @@ endif()
|
|||
# Building
|
||||
|
||||
set(SOURCES
|
||||
src/libc/assert/assert.c
|
||||
src/libc/stdio/vsnprintf.c
|
||||
src/libc/stdio/sprintf.c
|
||||
src/libc/stdio/dprintf.c
|
||||
|
|
27
include/assert.h
Normal file
27
include/assert.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
** assert.h> can be included several times and the assert macro is redefined
|
||||
** every time to match the definition of NDEBUG (7.2§1)
|
||||
*/
|
||||
#ifdef __ASSERT_H__
|
||||
# undef __ASSERT_H__
|
||||
# undef assert
|
||||
#endif
|
||||
|
||||
#define __ASSERT_H__
|
||||
|
||||
/* Internal function that prints error message and aborts */
|
||||
void __assert_fail(char const *__file, int __line, char const *__function,
|
||||
char const *__expression);
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assert(ignore) ((void)0)
|
||||
#else
|
||||
# define assert(expression) \
|
||||
((expression) \
|
||||
? (void)0 : \
|
||||
: __assert_fail(__FILE__, __LINE__, __PRETTY_FUNCTION__, #expression))
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
# define static_assert _Static_assert
|
||||
#endif
|
11
src/libc/assert/assert.c
Normal file
11
src/libc/assert/assert.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void __assert_fail(char const *file, int line, char const *func, char const
|
||||
*expression)
|
||||
{
|
||||
fprintf(stderr, "%s:%d:%s: assertion failed: %s\n",
|
||||
file, line, func, expression);
|
||||
abort();
|
||||
}
|
Loading…
Reference in a new issue