mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 17:27:37 -04:00
Add the standard assert() macro from the assert.h header. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260409-nolibc-assert-v1-1-42da8b367e23@weissschuh.net
37 lines
756 B
C
37 lines
756 B
C
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
|
/*
|
|
* Assert for NOLIBC
|
|
* Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
|
|
*/
|
|
|
|
/* make sure to include all global symbols */
|
|
#include "nolibc.h"
|
|
|
|
#ifndef _NOLIBC_ASSERT_H
|
|
#define _NOLIBC_ASSERT_H
|
|
|
|
#include "errno.h"
|
|
#include "stdio.h"
|
|
#include "stdlib.h"
|
|
|
|
#endif /* _NOLIBC_ASSERT_H */
|
|
|
|
/* NDEBUG needs to be evaluated on *each* inclusion */
|
|
#ifdef assert
|
|
#undef assert
|
|
#endif
|
|
|
|
#ifndef NDEBUG
|
|
#define assert(expr) \
|
|
({ \
|
|
if (!(expr)) { \
|
|
fprintf(stderr, "%s: %s:%d: %s: Assertion `%s' failed.\n", \
|
|
program_invocation_short_name, __FILE__, __LINE__, __func__, \
|
|
#expr); \
|
|
abort(); \
|
|
} \
|
|
})
|
|
#else
|
|
#define assert(expr) ((void)0)
|
|
#endif
|