diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-06-22 15:06:51 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-06-22 15:31:12 -0400 |
commit | 273b64322afa46c560dd74ea32f6c8ad26d93210 (patch) | |
tree | cc5e857990d0249e2f5b18c595a0bb39d5344f03 /src/diag.c | |
parent | a1490d98a1aebb3bfbd3873613977d0341ec7f98 (diff) | |
download | bfs-273b64322afa46c560dd74ea32f6c8ad26d93210.tar.xz |
diag: New bfs_loc type for source locations
Diffstat (limited to 'src/diag.c')
-rw-r--r-- | src/diag.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -5,6 +5,7 @@ #include "bfstd.h" #include "ctx.h" #include "color.h" +#include "config.h" #include "dstring.h" #include "expr.h" #include <errno.h> @@ -12,11 +13,26 @@ #include <stdlib.h> #include <string.h> -noreturn void bfs_abortf(const char *format, ...) { +noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) { + const char *cmd = NULL; +#if __GLIBC__ + cmd = program_invocation_short_name; +#elif BSD + cmd = getprogname(); +#endif + if (!cmd) { + cmd = BFS_COMMAND; + } + + fprintf(stderr, "%s: %s@%s:%d: ", cmd, loc->func, loc->file, loc->line); + va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); + + fprintf(stderr, "\n"); + abort(); } |