summaryrefslogtreecommitdiffstats
path: root/src/diag.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diag.c')
-rw-r--r--src/diag.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/diag.c b/src/diag.c
index ccafd98..a86b060 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -1,38 +1,43 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "diag.h"
+
#include "alloc.h"
+#include "bfs.h"
#include "bfstd.h"
#include "color.h"
#include "ctx.h"
#include "dstring.h"
#include "expr.h"
-#include <errno.h>
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-
-/** bfs_diagf() implementation. */
-attr(printf(2, 0))
-static void bfs_vdiagf(const struct bfs_loc *loc, const char *format, va_list args) {
- fprintf(stderr, "%s: %s@%s:%d: ", xgetprogname(), loc->func, loc->file, loc->line);
- vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
-}
-
-void bfs_diagf(const struct bfs_loc *loc, const char *format, ...) {
+#include <unistd.h>
+
+/**
+ * Print an error using dprintf() if possible, because it's more likely to be
+ * async-signal-safe in practice.
+ */
+#if BFS_HAS_DPRINTF
+# define veprintf(...) vdprintf(STDERR_FILENO, __VA_ARGS__)
+#else
+# define veprintf(...) vfprintf(stderr, __VA_ARGS__)
+#endif
+
+void bfs_diagf(const char *format, ...) {
va_list args;
va_start(args, format);
- bfs_vdiagf(loc, format, args);
+ veprintf(format, args);
va_end(args);
}
-noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
+_noreturn
+void bfs_abortf(const char *format, ...) {
va_list args;
va_start(args, format);
- bfs_vdiagf(loc, format, args);
+ veprintf(format, args);
va_end(args);
abort();