Base program_invocation_short_name on the source filename it is used in, as not to require argv[0] to be passed along. This approach is not dynamic, but doesn't require code changes for all places where program_invocation_short_name is used now. Signed-off-by: Fabian Groffen <grobian@xxxxxxxxxx> diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -211,6 +211,14 @@ [#include <sys/types.h> #include <sys/socket.h>]) +AC_MSG_CHECKING(whether program_invocation_short_name is defined) +AC_TRY_COMPILE([#include <argp.h>], + [program_invocation_short_name = "test";], + [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME, 1, + [Define if program_invocation_short_name is defined]) + AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no)]) + dnl Static compilation m4_define([UTIL_STATIC_PROGRAMS], [losetup, mount, umount, fdisk, sfdisk, blkid]) diff --git a/include/c.h b/include/c.h --- a/include/c.h +++ b/include/c.h @@ -69,5 +69,29 @@ return (num != 0 && ((num & (num - 1)) == 0)); } +#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME +#include <string.h> +#define program_invocation_short_name prog_inv_sh_nm_from_file(__FILE__) +static char prog_inv_sh_nm_buf[256]; +static inline char * +prog_inv_sh_nm_from_file(char *f) { + char *t; + + if ((t = strrchr(f, '/')) != NULL) { + t++; + } else { + t = f; + } + + strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1); + prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0'; + + if ((t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) + *t = '\0'; + + return prog_inv_sh_nm_buf; +} +#endif + #endif /* UTIL_LINUX_C_H */ -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html