From ced8ab50af1429d9ba7651da1b3b78014fd76e79 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 11 Nov 2024 10:22:26 -0700 Subject: libmisc: Write my own assert.h --- libmisc/assert.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 libmisc/assert.c (limited to 'libmisc/assert.c') 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 + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include /* for fprintf(), stderr */ +#include /* for abort() */ + +#include + +#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 -- cgit v1.2.3-2-g168b