summaryrefslogtreecommitdiff
path: root/libmisc/assert.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-12 12:46:15 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-12 12:46:49 -0700
commitaec7a1209a7c2314acc5703a94509a403c796444 (patch)
tree0bc2f20573becea8a032f495a2f7d8e9f3de2bda /libmisc/assert.c
parent3f66d2019879a4d3d97e43bd598e6286a21cc01d (diff)
Avoid using fprintf
Diffstat (limited to 'libmisc/assert.c')
-rw-r--r--libmisc/assert.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libmisc/assert.c b/libmisc/assert.c
index 987fb4d..9b1a0bc 100644
--- a/libmisc/assert.c
+++ b/libmisc/assert.c
@@ -4,20 +4,28 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-#include <stdio.h> /* for fprintf(), stderr */
-#include <stdlib.h> /* for abort() */
+#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) {
- fprintf(stderr, "error: %s:%u:%s(): assertion \"%s\" failed%s%s\n",
- file, line, func,
- expr,
- msg ? ": " : "", 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