@@ -132,6 +132,11 @@ then
AC_CHECK_FUNC([signalfd], [], [FUNC_NOT_FOUND_TOOLS([signalfd])])
AC_CHECK_FUNC([setlinebuf], [], [FUNC_NOT_FOUND_TOOLS([setlinebuf])])
AC_CHECK_HEADERS([sys/signalfd.h], [], [HEADER_NOT_FOUND_TOOLS([sys/signalfd.h])])
+ AC_CHECK_FUNC([getprogname],
+ [AC_DEFINE([HAVE_GETPROGNAME], 1, [Define to 1 if getprogname() is available.])],
+ [AC_CHECK_DECL([program_invocation_short_name], [],
+ [FUNC_NOT_FOUND_TOOLS([getprogname or program_invocation_short_name])],
+ [#include <errno.h>])])
fi
AC_ARG_ENABLE([tests],
@@ -22,7 +22,7 @@ static const char *const shortopts = "+hv";
static void print_help(void)
{
- printf("Usage: %s [OPTIONS]\n", get_progname());
+ printf("Usage: %s [OPTIONS]\n", getprogname());
printf("\n");
printf("List all GPIO chips, print their labels and number of GPIO lines.\n");
printf("\n");
@@ -50,7 +50,7 @@ int main(int argc, char **argv)
print_version();
return EXIT_SUCCESS;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -22,7 +22,7 @@ static const char *const shortopts = "+hv";
static void print_help(void)
{
- printf("Usage: %s [OPTIONS] <name>\n", get_progname());
+ printf("Usage: %s [OPTIONS] <name>\n", getprogname());
printf("\n");
printf("Find a GPIO line by name. The output of this command can be used as input for gpioget/set.\n");
printf("\n");
@@ -50,7 +50,7 @@ int main(int argc, char **argv)
print_version();
return EXIT_SUCCESS;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -26,7 +26,7 @@ static const char *const shortopts = "+hvlB:";
static void print_help(void)
{
printf("Usage: %s [OPTIONS] <chip name/number> <offset 1> <offset 2> ...\n",
- get_progname());
+ getprogname());
printf("\n");
printf("Read line value(s) from a GPIO chip\n");
printf("\n");
@@ -67,7 +67,7 @@ int main(int argc, char **argv)
flags = bias_flags(optarg);
break;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -73,7 +73,7 @@ static const char *const shortopts = "+hv";
static void print_help(void)
{
- printf("Usage: %s [OPTIONS] <gpiochip1> ...\n", get_progname());
+ printf("Usage: %s [OPTIONS] <gpiochip1> ...\n", getprogname());
printf("\n");
printf("Print information about all lines of the specified GPIO chip(s) (or all gpiochips if none are specified).\n");
printf("\n");
@@ -201,7 +201,7 @@ int main(int argc, char **argv)
print_version();
return EXIT_SUCCESS;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -35,7 +35,7 @@ static const char *const shortopts = "+hvlB:n:srfbF:";
static void print_help(void)
{
printf("Usage: %s [OPTIONS] <chip name/number> <offset 1> <offset 2> ...\n",
- get_progname());
+ getprogname());
printf("\n");
printf("Wait for events on GPIO lines and print them to standard output\n");
printf("\n");
@@ -275,7 +275,7 @@ int main(int argc, char **argv)
ctx.fmt = optarg;
break;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -35,7 +35,7 @@ static const char *const shortopts = "+hvlB:D:m:s:u:b";
static void print_help(void)
{
printf("Usage: %s [OPTIONS] <chip name/number> <offset1>=<value1> <offset2>=<value2> ...\n",
- get_progname());
+ getprogname());
printf("\n");
printf("Set GPIO line values of a GPIO chip and maintain the state until the process exits\n");
printf("\n");
@@ -242,7 +242,7 @@ int main(int argc, char **argv)
cbdata.daemonize = true;
break;
case '?':
- die("try %s --help", get_progname());
+ die("try %s --help", getprogname());
default:
abort();
}
@@ -19,17 +19,19 @@
#include "tools-common.h"
-const char *get_progname(void)
+#ifndef HAVE_GETPROGNAME
+const char *getprogname(void)
{
- return program_invocation_name;
+ return program_invocation_short_name;
}
+#endif
void die(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
- fprintf(stderr, "%s: ", program_invocation_name);
+ fprintf(stderr, "%s: ", getprogname());
vfprintf(stderr, fmt, va);
fprintf(stderr, "\n");
va_end(va);
@@ -42,7 +44,7 @@ void die_perror(const char *fmt, ...)
va_list va;
va_start(va, fmt);
- fprintf(stderr, "%s: ", program_invocation_name);
+ fprintf(stderr, "%s: ", getprogname());
vfprintf(stderr, fmt, va);
fprintf(stderr, ": %s\n", strerror(errno));
va_end(va);
@@ -53,7 +55,7 @@ void die_perror(const char *fmt, ...)
void print_version(void)
{
printf("%s (libgpiod) v%s\n",
- program_invocation_short_name, gpiod_version_string());
+ getprogname(), gpiod_version_string());
printf("Copyright (C) 2017-2018 Bartosz Golaszewski\n");
printf("License: LGPLv2.1\n");
printf("This is free software: you are free to change and redistribute it.\n");
@@ -21,7 +21,9 @@
#define GETOPT_NULL_LONGOPT NULL, 0, NULL, 0
-const char *get_progname(void);
+#ifndef HAVE_GETPROGNAME
+const char *getprogname(void);
+#endif
void die(const char *fmt, ...) NORETURN PRINTF(1, 2);
void die_perror(const char *fmt, ...) NORETURN PRINTF(1, 2);
void print_version(void);
Platforms like Bionic libc don't have program_invocation_[short_]name, which is a GNU extension. Use getprogname() from stdlib.h, another widely agreed extension, when it's available. It seemed a little heavyweight to add gnulib to this project's autotools set-up just for making one function portable, so I've just added the portabilty shim to tools-common.c for the moment. Signed-off-by: Benjamin Li <benl@squareup.com> --- configure.ac | 5 +++++ tools/gpiodetect.c | 4 ++-- tools/gpiofind.c | 4 ++-- tools/gpioget.c | 4 ++-- tools/gpioinfo.c | 4 ++-- tools/gpiomon.c | 4 ++-- tools/gpioset.c | 4 ++-- tools/tools-common.c | 12 +++++++----- tools/tools-common.h | 4 +++- 9 files changed, 27 insertions(+), 18 deletions(-)