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

#include <stdbool.h> /* for bool, true, false */
#include <stdlib.h>  /* for abort() */

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

#include <libmisc/assert.h>

#ifndef NDEBUG
[[noreturn, gnu::weak]]
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;
		errorf("%s:%u:%s(): assertion \"%s\" failed%s%s",
		       file, line, func,
		       expr,
		       msg ? ": " : "", msg ?: "");
		in_fail = false;
	}
	abort();
}
#endif