summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bfstd.c15
-rw-r--r--src/bfstd.h8
-rw-r--r--src/diag.c12
3 files changed, 24 insertions, 11 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 0e8ba5f..1f4bbb2 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -143,6 +143,21 @@ char *xgetdelim(FILE *file, char delim) {
}
}
+const char *xgetprogname(void) {
+ const char *cmd = NULL;
+#if __GLIBC__
+ cmd = program_invocation_short_name;
+#elif BSD
+ cmd = getprogname();
+#endif
+
+ if (!cmd) {
+ cmd = BFS_COMMAND;
+ }
+
+ return cmd;
+}
+
/** Compile and execute a regular expression for xrpmatch(). */
static int xrpregex(nl_item item, const char *response) {
const char *pattern = nl_langinfo(item);
diff --git a/src/bfstd.h b/src/bfstd.h
index cafe28f..ebbcdb9 100644
--- a/src/bfstd.h
+++ b/src/bfstd.h
@@ -106,6 +106,14 @@ char *xgetdelim(FILE *file, char delim);
// #include <stdlib.h>
/**
+ * Wrapper for getprogname() or equivalent functionality.
+ *
+ * @return
+ * The basename of the currently running program.
+ */
+const char *xgetprogname(void);
+
+/**
* Process a yes/no prompt.
*
* @return 1 for yes, 0 for no, and -1 for unknown.
diff --git a/src/diag.c b/src/diag.c
index 99b487a..acea9ad 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -14,17 +14,7 @@
#include <string.h>
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);
+ fprintf(stderr, "%s: %s@%s:%d: ", xgetprogname(), loc->func, loc->file, loc->line);
va_list args;
va_start(args, format);