summaryrefslogtreecommitdiff
path: root/libmisc/assert.c
blob: 85d167da91d45da873d837092fc83b29a1d1d56c (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
/* libmisc/assert.c - More assertions
 *
 * Copyright (C) 2024-2025  Luke T. Shumaker <lukeshu@lukeshu.com>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#include <libmisc/_intercept.h> /* for __lm_abort() */

#define LOG_NAME ASSERT
#include <libmisc/log.h> /* for log_errorln() */

#include <libmisc/assert.h>

#ifndef NDEBUG
void __assert_msg_fail(const char *expr,
                       const char *file, unsigned int line, const char *func,
                       const char *msg) {
	static bool in_fail = false;
	if (!in_fail) {
		in_fail = true;
		log_errorln(file, ":", line, ":", func, "(): ",
		            "assertion \"", (str, expr), "\" failed",
		            msg ? ": " : "", msg ?: "");
		in_fail = false;
	}
	__lm_abort();
}
#endif