Skip to content

Commit

Permalink
configure/getprogname: fix handling and use __progname too
Browse files Browse the repository at this point in the history
1. fix the handling of the fallbacks in getprogname
   i.e. actually use the fallback
2. add a check for __progname too

See #35
  • Loading branch information
omar-polo committed Aug 5, 2024
1 parent e27216e commit 0cf61ff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
16 changes: 14 additions & 2 deletions compat/getprogname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,23 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions have/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 11 additions & 0 deletions have/__progname.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* public domain */

#include <stdio.h>

extern const char *__progname;

int
main(void)
{
puts(__progname);
}

0 comments on commit 0cf61ff

Please sign in to comment.