summaryrefslogtreecommitdiff
path: root/libmisc/assert.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-11 10:22:26 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-11 19:19:48 -0700
commit6ae2bbf849aa597054d7c84d20fc634ed87a1da5 (patch)
treec1deed14207996f685f28a5fb5d553db130d205c /libmisc/assert.c
parentda46fcb709b9df47d788341b3bd87c545f720f4f (diff)
libmisc: Write my own assert.h with assert_notreached()
Diffstat (limited to 'libmisc/assert.c')
-rw-r--r--libmisc/assert.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/libmisc/assert.c b/libmisc/assert.c
new file mode 100644
index 0000000..7817ba3
--- /dev/null
+++ b/libmisc/assert.c
@@ -0,0 +1,23 @@
+/* libmisc/assert.h - More assertions
+ *
+ * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <stdio.h> /* for fprintf(), stderr */
+#include <stdlib.h> /* for abort() */
+
+#include <libmisc/assert.h>
+
+#ifndef NDEBUG
+__attribute__((__noreturn__)) void
+__assert_msg_fail(const char *expr,
+ const char *file, unsigned int line, const char *func,
+ const char *msg) {
+ fprintf(stderr, "error: %s:%u:%s(): assertion \"%s\" failed%s%s\n",
+ file, line, func,
+ expr,
+ msg ? ": " : "", msg);
+ abort();
+}
+#endif