summaryrefslogtreecommitdiff
path: root/libmisc/assert.c
blob: 9b1a0bc5ad27bd60213cc05adb29f2a3e73e68bf (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 <stdio.h>   /* for printf() */
#include <stdlib.h>  /* for abort() */

#include <libmisc/assert.h>

#ifndef NDEBUG

static bool in_fail = false;

__attribute__((__noreturn__)) void
__assert_msg_fail(const char *expr,
                  const char *file, unsigned int line, const char *func,
                  const char *msg) {
	if (!in_fail) {
		in_fail = true;
		printf("error: %s:%u:%s(): assertion \"%s\" failed%s%s\n",
		       file, line, func,
		       expr,
		       msg ? ": " : "", msg);
	}
	abort();
}

#endif