mirror of
https://github.com/nilfs-dev/nilfs-utils.git
synced 2026-01-26 13:43:15 +00:00
build: add portable getprogname() support
Add a compatibility layer for getprogname() to allow utilities to retrieve the short program name uniformly, removing the need for manual argv[0] parsing. The logic prioritizes the GNU extension variable 'program_invocation_short_name', falling back to getprogname. If neither is available, the build fails with an #error. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This commit is contained in:
parent
a421d4f6e7
commit
67c58a898d
@ -182,6 +182,13 @@ elif test -f /etc/mtab; then
|
||||
mtab_type=file
|
||||
fi
|
||||
|
||||
# Check program_invocation_short_name and getprogname()
|
||||
AC_CHECK_DECLS([program_invocation_short_name], [], [],
|
||||
[[#include <errno.h>]])
|
||||
|
||||
AS_IF([test "x$ac_cv_have_decl_program_invocation_short_name" != "xyes"],
|
||||
[AC_CHECK_FUNCS([getprogname])])
|
||||
|
||||
# Check for conditional libraries and headers.
|
||||
AS_IF([test "${with_blkid}" = "yes"], [
|
||||
NILFS_UTILS_PKG_CHECK([BLKID], [blkid], [
|
||||
|
||||
@ -203,4 +203,14 @@
|
||||
#endif /* HAVE_SYS_SYSMACROS_H */
|
||||
|
||||
|
||||
#ifndef HAVE_GETPROGNAME
|
||||
#if defined(HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) && \
|
||||
HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||
#include <errno.h>
|
||||
#define getprogname() ((const char *)program_invocation_short_name)
|
||||
#else
|
||||
#error "No way to retrieve the program name"
|
||||
#endif
|
||||
#endif /* HAVE_GETPROGNAME */
|
||||
|
||||
#endif /* __COMPAT_H__ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user