From 732ad2d90e0ae27a774c6c61f2cf925610b193de Mon Sep 17 00:00:00 2001 From: Vadim Mikhailov Date: Thu, 22 Sep 2022 11:21:32 -0700 Subject: [PATCH] Fix crash on non-Linux if -S is used Also move short options near long options table so it is easier to maintain. --- uhubctl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/uhubctl.c b/uhubctl.c index 7bc1532..b66de3c 100644 --- a/uhubctl.c +++ b/uhubctl.c @@ -230,6 +230,14 @@ static int opt_nodesc = 0; /* skip querying device description */ static int opt_nosysfs = 0; /* don't use the Linux sysfs port disable interface, even if available */ #endif + +static const char short_options[] = + "l:L:n:a:p:d:r:w:s:hvefRN" +#ifdef __gnu_linux__ + "S" +#endif +; + static const struct option long_options[] = { { "location", required_argument, NULL, 'l' }, { "vendor", required_argument, NULL, 'n' }, @@ -1021,8 +1029,7 @@ int main(int argc, char *argv[]) int option_index = 0; for (;;) { - c = getopt_long(argc, argv, "l:L:n:a:p:d:r:w:s:hvefRNS", - long_options, &option_index); + c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == -1) break; /* no more options left */ switch (c) {