summaryrefslogtreecommitdiff
path: root/tools/include/nolibc/assert.h
blob: 84ff8ad9ab0778364600bb83e1af2d066ba5c0de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* 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