From 4b3f4aa77a3265f3b7547a576a1a0411b6a6fb8c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 10 Mar 2024 18:59:00 +0100 Subject: Rename [set]progname() to mlib_[set]progname() This namespacing was done because of a potential conflict with the setprogname() function available in as part of BSD systems. --- include/errors.h | 6 +++--- lib/errors/mlib_setprogname.c | 12 ++++++++++++ lib/errors/setprogname.c | 12 ------------ lib/errors/vwarn.c | 2 +- lib/errors/vwarnx.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 lib/errors/mlib_setprogname.c delete mode 100644 lib/errors/setprogname.c diff --git a/include/errors.h b/include/errors.h index 975fac4..6721afa 100644 --- a/include/errors.h +++ b/include/errors.h @@ -3,8 +3,6 @@ #include -void setprogname(const char *); - [[gnu::format(printf, 1, 2)]] void warn(const char *, ...); [[gnu::format(printf, 1, 2)]] void warnx(const char *, ...); void vwarn(const char *, va_list); @@ -17,9 +15,11 @@ void vwarnx(const char *, va_list); extern const char *__mlib_errors_progname; +void mlib_setprogname(const char *); + [[gnu::always_inline]] static inline const char * -progname(void) +mlib_progname(void) { return __mlib_errors_progname; } diff --git a/lib/errors/mlib_setprogname.c b/lib/errors/mlib_setprogname.c new file mode 100644 index 0000000..bfc77b0 --- /dev/null +++ b/lib/errors/mlib_setprogname.c @@ -0,0 +1,12 @@ +#include + +#include "errors.h" + +const char *__mlib_errors_progname; + +void +mlib_setprogname(const char *s) +{ + const char *p = strrchr(s, '/'); + __mlib_errors_progname = p ? p + 1 : s; +} diff --git a/lib/errors/setprogname.c b/lib/errors/setprogname.c deleted file mode 100644 index ab2de3e..0000000 --- a/lib/errors/setprogname.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "errors.h" - -const char *__mlib_errors_progname; - -void -setprogname(const char *s) -{ - const char *p = strrchr(s, '/'); - __mlib_errors_progname = p ? p + 1 : s; -} diff --git a/lib/errors/vwarn.c b/lib/errors/vwarn.c index bc6bd16..99b2c9b 100644 --- a/lib/errors/vwarn.c +++ b/lib/errors/vwarn.c @@ -9,7 +9,7 @@ void vwarn(const char *fmt, va_list ap) { int save = errno; - fprintf(stderr, "%s: ", progname()); + fprintf(stderr, "%s: ", mlib_progname()); vfprintf(stderr, fmt, ap); fprintf(stderr, ": %s\n", strerror(save)); } diff --git a/lib/errors/vwarnx.c b/lib/errors/vwarnx.c index 72d8fa7..58a7bc6 100644 --- a/lib/errors/vwarnx.c +++ b/lib/errors/vwarnx.c @@ -6,7 +6,7 @@ void vwarnx(const char *fmt, va_list ap) { - fprintf(stderr, "%s: ", progname()); + fprintf(stderr, "%s: ", mlib_progname()); vfprintf(stderr, fmt, ap); fputc('\n', stderr); } -- cgit v1.2.3