summaryrefslogtreecommitdiffstats
path: root/src/diag.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-29 13:16:14 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-29 13:25:24 -0500
commita228788769d7e3c71154606609a13eafb03a5fc2 (patch)
treed78e7495df29767f5cf3a044bbe4271eaf0a6af7 /src/diag.c
parente6d80d04d6928c452b48eae717373bf6a943e355 (diff)
downloadbfs-a228788769d7e3c71154606609a13eafb03a5fc2.tar.xz
diag: New bfs_diag() macro
Diffstat (limited to 'src/diag.c')
-rw-r--r--src/diag.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/diag.c b/src/diag.c
index efa7ebd..656fa89 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -14,15 +14,26 @@
#include <stdlib.h>
#include <string.h>
-noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
+/** 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, ...) {
va_list args;
va_start(args, format);
- vfprintf(stderr, format, args);
+ bfs_vdiagf(loc, format, args);
va_end(args);
+}
- fprintf(stderr, "\n");
+noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
+ va_list args;
+ va_start(args, format);
+ bfs_vdiagf(loc, format, args);
+ va_end(args);
abort();
}