tools: use basename(argv[0]) for program name
authorNiclas Zeising <zeising@daemonic.se>
Tue, 28 Jul 2020 16:22:08 +0000 (18:22 +0200)
committerNiclas Zeising <zeising@daemonic.se>
Fri, 14 Aug 2020 15:50:56 +0000 (17:50 +0200)
Use baename(argv[0]) to get the program name (for usage), instead of
using program_invocation_short_name, which only exists on Linux, not
FreeBSD.

Signed-off-by: Niclas Zeising <zeising@daemonic.se>
tools/libevdev-tweak-device.c
tools/mouse-dpi-tool.c
tools/touchpad-edge-detector.c

index 38e4021..391c5f9 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include <getopt.h>
+#include <libgen.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -39,7 +40,7 @@
 #include "libevdev/libevdev.h"
 
 static void
-usage(void)
+usage(const char *progname)
 {
        printf("%s --abs <axis> [--min min] [--max max] [--res res] [--fuzz fuzz] [--flat flat] /dev/input/eventXYZ\n"
               "\tChange the absinfo struct for the named axis\n"
@@ -47,9 +48,9 @@ usage(void)
               "\tChange the x/y resolution on the given device\n"
               "%s --led <led> --on|--off /dev/input/eventXYZ\n"
               "\tEnable or disable the named LED\n",
-              program_invocation_short_name,
-              program_invocation_short_name,
-              program_invocation_short_name);
+              progname,
+              progname,
+              progname);
 }
 
 enum mode {
@@ -415,7 +416,7 @@ main(int argc, char **argv)
                        rc = EXIT_SUCCESS;
                        /* fallthrough */
                case MODE_NONE:
-                       usage();
+                       usage(basename(argv[0]));
                        goto out;
                case MODE_ABS:
                        rc = parse_options_abs(argc, argv, &changes, &axis,
@@ -439,7 +440,7 @@ main(int argc, char **argv)
 
        if (optind >= argc) {
                rc = EXIT_FAILURE;
-               usage();
+               usage(basename(argv[0]));
                goto out;
        }
 
index 911f61e..55e84f2 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <limits.h>
 #include <poll.h>
 #include <signal.h>
@@ -51,8 +52,8 @@ struct measurements {
 };
 
 static int
-usage(void) {
-       printf("Usage: %s /dev/input/event0\n", program_invocation_short_name);
+usage(const char *progname) {
+       printf("Usage: %s /dev/input/event0\n", progname);
        printf("\n");
        printf("This tool reads relative events from the kernel and calculates\n"
               "the distance covered and maximum frequency of the incoming events.\n"
@@ -262,11 +263,11 @@ main (int argc, char **argv) {
        struct measurements measurements = {0};
 
        if (argc < 2)
-               return usage();
+               return usage(basename(argv[0]));
 
        path = argv[1];
        if (path[0] == '-')
-               return usage();
+               return usage(basename(argv[0]));
 
        fd = open(path, O_RDONLY|O_NONBLOCK);
        if (fd < 0) {
index 7727cad..2e0c9fe 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <limits.h>
 #include <math.h>
 #include <poll.h>
@@ -43,8 +44,8 @@
 static int signalled = 0;
 
 static int
-usage(void) {
-       printf("Usage: %s 12x34 /dev/input/eventX\n", program_invocation_short_name);
+usage(const char *progname) {
+       printf("Usage: %s 12x34 /dev/input/eventX\n", progname);
        printf("\n");
        printf("This tool reads the touchpad events from the kernel and calculates\n "
               "the minimum and maximum for the x and y coordinates, respectively.\n"
@@ -236,11 +237,11 @@ int main (int argc, char **argv) {
        struct size size;
 
        if (argc < 3)
-               return usage();
+               return usage(basename(argv[0]));
 
        if (sscanf(argv[1], "%dx%d", &size.w, &size.h) != 2 ||
            size.w <= 0 || size.h <= 0)
-               return usage();
+               return usage(basename(argv[0]));
 
        if (size.w < 30 || size.h < 30) {
                fprintf(stderr,
@@ -252,7 +253,7 @@ int main (int argc, char **argv) {
 
        path = argv[2];
        if (path[0] == '-')
-               return usage();
+               return usage(basename(argv[0]));
 
        fd = open(path, O_RDONLY|O_NONBLOCK);
        if (fd < 0) {