From: Emil Velikov Date: Sat, 19 Oct 2024 17:11:17 +0000 (+0100) Subject: tools/insmod: minor getopt tweaks X-Git-Tag: v34~204 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b14c16ba373aabc92dbf04a20281bc9a3710861e;p=thirdparty%2Fkmod.git tools/insmod: minor getopt tweaks Pull the unistd.h for optind and adjust the loop to follow the in-documentation example. Namely, we don't need the unused idx and removing the seemingly infinite loop helps static analysers better reason about the code flow. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/195 Signed-off-by: Lucas De Marchi --- diff --git a/tools/insmod.c b/tools/insmod.c index b3d01c6a..74669a93 100644 --- a/tools/insmod.c +++ b/tools/insmod.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -66,15 +67,11 @@ static int do_insmod(int argc, char *argv[]) size_t optslen = 0; int verbose = LOG_ERR; int use_syslog = 0; - int i, r = 0; + int i, c, r = 0; const char *null_config = NULL; unsigned int flags = 0; - for (;;) { - int c, idx = 0; - c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx); - if (c == -1) - break; + while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, NULL)) != -1) { switch (c) { case 'f': flags |= KMOD_PROBE_FORCE_MODVERSION;