summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Cutts <hcutts@google.com>2023-10-09 17:22:09 +0000
committerHarry Cutts <hcutts@google.com>2023-10-09 17:22:09 +0000
commit13aa59c62df79bac2a75dcd640d5b5724325db6f (patch)
tree269fac5507096cfa69b48bf446d60342b3709e80
parent86a5627dbeac8d9d9bc34326a758d6a477e876e4 (diff)
tools: use basename(argv[0]) instead of program_invocation_short_name
program_invocation_short_name is a GNU-specific extension of the C library, and therefore isn't available when compiling with other implementations. Signed-off-by: Harry Cutts <hcutts@google.com>
-rw-r--r--tools/evemu-event.c16
-rw-r--r--tools/evemu-play.c3
-rw-r--r--tools/evemu-record.c13
3 files changed, 18 insertions, 14 deletions
diff --git a/tools/evemu-event.c b/tools/evemu-event.c
index ce928ac..7b968c3 100644
--- a/tools/evemu-event.c
+++ b/tools/evemu-event.c
@@ -22,6 +22,7 @@
#include "evemu.h"
#include <getopt.h>
+#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <fcntl.h>
@@ -67,9 +68,9 @@ static int parse_code(long int type, const char *arg, long int *value)
return parse_arg(arg, value);
}
-static void usage(void)
+static void usage(const char *program_name)
{
- fprintf(stderr, "Usage: %s [--sync] <device> --type <type> --code <code> --value <value>\n", program_invocation_short_name);
+ fprintf(stderr, "Usage: %s [--sync] <device> --type <type> --code <code> --value <value>\n", program_name);
}
int main(int argc, char *argv[])
@@ -79,11 +80,12 @@ int main(int argc, char *argv[])
long int type, code, value = LONG_MAX;
struct input_event ev;
int sync = 0;
+ const char *program_name = basename(argv[0]);
const char *path = NULL;
const char *code_arg = NULL, *type_arg = NULL;
if (argc < 5) {
- usage();
+ usage(program_name);
goto out;
}
@@ -115,13 +117,13 @@ int main(int argc, char *argv[])
sync = 1;
break;
default:
- usage();
+ usage(program_name);
goto out;
}
}
if (!type_arg || !code_arg || value == LONG_MAX) {
- usage();
+ usage(program_name);
goto out;
}
@@ -138,7 +140,7 @@ int main(int argc, char *argv[])
/* if device wasn't specified as option, take the remaining arg */
if (optind < argc) {
if (argc - optind != 1 || path) {
- usage();
+ usage(program_name);
goto out;
}
path = argv[optind];
@@ -146,7 +148,7 @@ int main(int argc, char *argv[])
if (!path) {
fprintf(stderr, "error: missing device path\n");
- usage();
+ usage(program_name);
goto out;
}
diff --git a/tools/evemu-play.c b/tools/evemu-play.c
index 989d973..776843d 100644
--- a/tools/evemu-play.c
+++ b/tools/evemu-play.c
@@ -44,6 +44,7 @@
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
+#include <libgen.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -253,7 +254,7 @@ static int play(int argc, char *argv[])
int main(int argc, char *argv[])
{
- const char *prgm_name = program_invocation_short_name;
+ const char *prgm_name = basename(argv[0]);
if (prgm_name &&
(strcmp(prgm_name, "evemu-device") == 0 ||
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index 64a32ad..09820a2 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -43,6 +43,7 @@
#include "evemu.h"
#include <assert.h>
#include <getopt.h>
+#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@@ -107,10 +108,10 @@ static inline bool safe_atoi(const char *str, int *val)
return true;
}
-static inline void usage()
+static inline void usage(const char *program_name)
{
fprintf(stderr, "Usage: %s [--autorestart=s] <device> [output file]\n",
- program_invocation_short_name);
+ program_name);
fprintf(stderr, "Options:\n");
fprintf(stderr, " --autorestart=s\n");
fprintf(stderr, " Terminate the current recording after <s> seconds\n"
@@ -236,7 +237,7 @@ int main(int argc, char *argv[])
enum mode mode = EVEMU_RECORD;
int fd = -1;
struct sigaction act;
- char *prgm_name = program_invocation_short_name;
+ char *prgm_name = basename(argv[0]);
char *device = NULL;
int timeout = INFINITE;
struct option opts[] = {
@@ -265,14 +266,14 @@ int main(int argc, char *argv[])
case OPT_AUTORESTART:
if (!safe_atoi(optarg, &timeout) ||
timeout <= 0) {
- usage();
+ usage(prgm_name);
goto out;
}
timeout *= 1000; /* sec to ms */
autorestart = true;
break;
default:
- usage();
+ usage(prgm_name);
goto out;
}
}
@@ -280,7 +281,7 @@ int main(int argc, char *argv[])
device = (optind >= argc) ? find_event_devices() : strdup(argv[optind++]);
if (device == NULL) {
- usage();
+ usage(prgm_name);
goto out;
}
fd = open(device, O_RDONLY | O_NONBLOCK);