summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/diag.c17
-rw-r--r--src/diag.h13
2 files changed, 27 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();
}
diff --git a/src/diag.h b/src/diag.h
index 791c065..4054c48 100644
--- a/src/diag.h
+++ b/src/diag.h
@@ -42,6 +42,19 @@ struct bfs_loc {
#endif
/**
+ * Print a low-level diagnostic message to standard error, formatted like
+ *
+ * bfs: func@src/file.c:0: Message
+ */
+attr(printf(2, 3))
+void bfs_diagf(const struct bfs_loc *loc, const char *format, ...);
+
+/**
+ * Unconditional diagnostic message.
+ */
+#define bfs_diag(...) bfs_diagf(bfs_location(), __VA_ARGS__)
+
+/**
* Print a message to standard error and abort.
*/
attr(cold, printf(2, 3))