From: Masatake YAMATO Date: Sun, 5 Mar 2023 03:44:37 +0000 (+0900) Subject: lsfd: simplify functions for comparing items X-Git-Tag: v2.39-rc1~12^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0caccbf1a006d0690ac5fc50325ba8c2e9b9f18a;p=thirdparty%2Futil-linux.git lsfd: simplify functions for comparing items Suggested-by: Thomas Weißschuh Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c index 4e2d7cce68..db3d3bf4c6 100644 --- a/misc-utils/lsfd-sock-xinfo.c +++ b/misc-utils/lsfd-sock-xinfo.c @@ -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) diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index a0e9f9e782..184250c39a 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -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)