]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: simplify functions for comparing items
authorMasatake YAMATO <yamato@redhat.com>
Sun, 5 Mar 2023 03:44:37 +0000 (12:44 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 5 Mar 2023 18:17:30 +0000 (03:17 +0900)
Suggested-by: Thomas Weißschuh <thomas@t-8ch.de>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock-xinfo.c
misc-utils/lsfd.c

index 4e2d7cce6847b62c5127f6496e338dafa9abb7f6..db3d3bf4c64607d5b874a97fd0b9b9426c1cce69 100644 (file)
@@ -61,12 +61,7 @@ static void *netns_tree;
 
 static int netns_compare(const void *a, const void *b)
 {
-       if (*(ino_t *)a < *(ino_t *)b)
-               return -1;
-       else if (*(ino_t *)a > *(ino_t *)b)
-               return 1;
-       else
-               return 0;
+       return *(ino_t *)a - *(ino_t *)b;
 }
 
 static bool is_sock_xinfo_loaded(ino_t netns)
@@ -194,11 +189,7 @@ void finalize_sock_xinfos(void)
 
 static int xinfo_compare(const void *a, const void *b)
 {
-       if (((struct sock_xinfo *)a)->inode < ((struct sock_xinfo *)b)->inode)
-               return -1;
-       if (((struct sock_xinfo *)a)->inode > ((struct sock_xinfo *)b)->inode)
-               return 1;
-       return 0;
+       return ((struct sock_xinfo *)a)->inode - ((struct sock_xinfo *)b)->inode;
 }
 
 static void add_sock_info(struct sock_xinfo *xinfo)
index a0e9f9e782c8c64dc320faa2768e8be8a71ca9f6..184250c39a6f31a6ff257a8bc79a76ab5ac9b4c4 100644 (file)
@@ -447,11 +447,7 @@ static void *proc_tree;                    /* for tsearch/tfind */
 
 static int proc_tree_compare(const void *a, const void *b)
 {
-       if (((struct proc *)a)->pid < ((struct proc *)b)->pid)
-               return -1;
-       if (((struct proc *)a)->pid > ((struct proc *)b)->pid)
-               return 1;
-       return 0;
+       return ((struct proc *)a)->pid - ((struct proc *)b)->pid;
 }
 
 struct proc *get_proc(pid_t pid)