From f676cc7bb821f498efe73f38bf19b43e4b91f575 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 28 May 2020 19:41:02 +0200 Subject: Added assertion to userspace --- src/userspace/libc/assert.h | 8 ++++++++ src/userspace/libc/assert/assert.c | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/userspace/libc/assert.h create mode 100644 src/userspace/libc/assert/assert.c (limited to 'src') diff --git a/src/userspace/libc/assert.h b/src/userspace/libc/assert.h new file mode 100644 index 0000000..5ff70ab --- /dev/null +++ b/src/userspace/libc/assert.h @@ -0,0 +1,8 @@ +#ifndef MELVIX_ASSERT_H +#define MELVIX_ASSERT_H + +#define __FILENAME__ \ + (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) +#define assert(exp) (exp) ? 0 : _assert(__FILENAME__, __LINE__, __func__, #exp) + +#endif \ No newline at end of file diff --git a/src/userspace/libc/assert/assert.c b/src/userspace/libc/assert/assert.c new file mode 100644 index 0000000..efd9083 --- /dev/null +++ b/src/userspace/libc/assert/assert.c @@ -0,0 +1,8 @@ +#include +#include + +void _assert(const char *file, int line, const char *func, const char *exp) +{ + printf("%s:%d: %s: Assertion '%s' failed", file, line, func, exp); + exit(1); +} \ No newline at end of file -- cgit v1.2.3