From f00e74260da0b94c325e169e05010af682a8d910 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 16 Jun 2022 14:17:32 +0100 Subject: [PATCH] Implemented assert() --- photon/libc/include/assert.h | 8 ++++++++ photon/libc/stdlib/assert.c | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 photon/libc/include/assert.h create mode 100644 photon/libc/stdlib/assert.c diff --git a/photon/libc/include/assert.h b/photon/libc/include/assert.h new file mode 100644 index 0000000..c1b23b6 --- /dev/null +++ b/photon/libc/include/assert.h @@ -0,0 +1,8 @@ +#ifndef PHOTON_ASSERT_H_ +#define PHOTON_ASSERT_H_ + +#define assert(x) if (!(x)) { __assert_fail(#x, __FUNCTION__, __FILE__, __LINE__); } + +extern void _Noreturn __assert_fail(const char *, const char *, const char *, int); + +#endif diff --git a/photon/libc/stdlib/assert.c b/photon/libc/stdlib/assert.c new file mode 100644 index 0000000..3c8dde4 --- /dev/null +++ b/photon/libc/stdlib/assert.c @@ -0,0 +1,8 @@ +#include +#include + +extern void _Noreturn __assert_fail(const char *exp, const char *func, const char *file, int line) +{ + printf("Assertion failed: (%s), function %s, file %s, line %d\n", exp, func, file, line); + abort(); +}