aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2024-08-05 18:10:36 +0000
committerOmar Polo <op@omarpolo.com>2024-08-05 18:10:36 +0000
commit0cf61ffcaf5321ee5888f5c1d247a1c383ff75fd (patch)
treed1430ddbab7911e79c083b2b86ad2a751311bc98
parente27216e1c5bbaeb1074d4c65f38aa9b2072940ed (diff)
configure/getprogname: fix handling and use __progname too
1. fix the handling of the fallbacks in getprogname i.e. actually use the fallback 2. add a check for __progname too See https://github.com/omar-polo/gmid/issues/35
-rw-r--r--compat/getprogname.c16
-rwxr-xr-xconfigure9
-rw-r--r--have/Makefile1
-rw-r--r--have/__progname.c11
4 files changed, 33 insertions, 4 deletions
diff --git a/compat/getprogname.c b/compat/getprogname.c
index ea7c2a3..7386263 100644
--- a/compat/getprogname.c
+++ b/compat/getprogname.c
@@ -16,7 +16,19 @@
#include "../config.h"
-#if HAVE_PROGRAM_INVOCATION_SHORT_NAME
+#if HAVE___PROGNAME
+
+#include <stddef.h>
+
+extern char *__progname;
+
+const char *
+getprogname(void)
+{
+ return __progname;
+}
+
+#elif HAVE_PROGRAM_INVOCATION_SHORT_NAME
#include <errno.h>
@@ -29,7 +41,7 @@ getprogname(void)
}
#else
-
+# warning Found no way to get the program name, will use "gmid" for all utilities.
const char *
getprogname(void)
{
diff --git a/configure b/configure
index 297f2b5..6aa6128 100755
--- a/configure
+++ b/configure
@@ -287,6 +287,10 @@ if [ ${HAVE_ENDIAN_H} -eq 0 -a \
exit 1
fi
+runtest getprogname GETPROGNAME || \
+runtest __progname __PROGNAME || \
+runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME -D_GNU_SOURCE || true
+
runtest arc4random ARC4RANDOM || true
runtest arc4random_buf ARC4RANDOM_BUF || true
runtest err ERR || true
@@ -294,14 +298,12 @@ runtest explicit_bzero EXPLICIT_BZERO || true
runtest freezero FREEZERO || true
runtest getdtablecount GETDTABLECOUNT || true
runtest getdtablesize GETDTABLESIZE || true
-runtest getprogname GETPROGNAME || true
runtest imsg IMSG "" -lutil libimsg || true
runtest landlock LANDLOCK || true
runtest libevent LIBEVENT "" -levent libevent_core|| true
runtest memmem MEMMEM -D_GNU_SOURCE || true
runtest openssl OPENSSL "" '-lcrypto -lssl' 'libcrypto libssl' || true
runtest pr_set_name PR_SET_NAME || true
-runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME -D_GNU_SOURCE || true
runtest queue_h QUEUE_H || true
runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
runtest recallocarray RECALLOCARRAY || true
@@ -448,6 +450,9 @@ cat <<__HEREDOC__
# define SYSCONFDIR "${SYSCONFDIR}"
#endif
+#define HAVE___PROGNAME ${HAVE___PROGNAME:-0}
+#define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME:-0}
+
__HEREDOC__
if [ ${HAVE_ENDIAN_H} -eq 1 ]; then
diff --git a/have/Makefile b/have/Makefile
index bc9d7c5..3bb5f8f 100644
--- a/have/Makefile
+++ b/have/Makefile
@@ -5,6 +5,7 @@ DISTFILES = ASN1_time_parse.c \
SSL_CTX_load_verify_mem.c \
SSL_CTX_use_certificate_chain_mem.c \
X509_LOOKUP_mem.c \
+ __progname.c \
arc4random.c \
arc4random_buf.c \
endian_h.c \
diff --git a/have/__progname.c b/have/__progname.c
new file mode 100644
index 0000000..dbef94c
--- /dev/null
+++ b/have/__progname.c
@@ -0,0 +1,11 @@
+/* public domain */
+
+#include <stdio.h>
+
+extern const char *__progname;
+
+int
+main(void)
+{
+ puts(__progname);
+}