]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
lsmod: Simplify code
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 22 Dec 2024 16:24:57 +0000 (17:24 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sun, 22 Dec 2024 21:19:01 +0000 (15:19 -0600)
Reduces cyclomatic complexity and binary size.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/271
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/lsmod.c

index ef5a08c927856736721beb7ef9fcdc447ac2f323..ea68d1dcefb89896b8fd06ef59bfdf166aac784a 100644 (file)
@@ -101,19 +101,15 @@ static int do_lsmod(int argc, char *argv[])
                int use_count = kmod_module_get_refcnt(mod);
                long size = kmod_module_get_size(mod);
                struct kmod_list *holders, *hitr;
-               int first = 1;
+               int sep = ' ';
 
                printf("%-19s %8ld  %d", name, size, use_count);
                holders = kmod_module_get_holders(mod);
                kmod_list_foreach(hitr, holders) {
                        struct kmod_module *hm = kmod_module_get_module(hitr);
 
-                       if (!first) {
-                               putchar(',');
-                       } else {
-                               putchar(' ');
-                               first = 0;
-                       }
+                       putchar(sep);
+                       sep = ',';
 
                        fputs(kmod_module_get_name(hm), stdout);
                        kmod_module_unref(hm);