]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lastlog2: convert check_user() to boolean-like macro
authorKarel Zak <kzak@redhat.com>
Tue, 20 Feb 2024 09:37:02 +0000 (10:37 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Feb 2024 09:50:09 +0000 (10:50 +0100)
Let's make simple and stupid.

Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit af93603e52d56fdd6246a038139a5d0e83a5c6a2)

misc-utils/lastlog2.c

index 91bb98caf44117b4607c8484af0c42579074b012..4029f5e48edb1ed11ec5cac73f31a864ece416ac 100644 (file)
@@ -125,14 +125,8 @@ static void __attribute__((__noreturn__)) usage(void)
        exit(EXIT_SUCCESS);
 }
 
-/* Check if an user exists on the system.
-   If yes, return 0, else return -1. */
-static int check_user(const char *name)
-{
-       if (getpwnam(name) == NULL)
-               return -1;
-       return 0;
-}
+/* Check if an user exists on the system */
+#define has_user(_x)   (getpwnam(_x) != NULL)
 
 int main(int argc, char **argv)
 {
@@ -242,7 +236,7 @@ int main(int argc, char **argv)
                        goto err;
                }
 
-               if ((Cflg || Sflg) && check_user(user) != 0) {
+               if ((Cflg || Sflg) && !has_user(user)) {
                        warnx(_("User '%s' does not exist."), user);
                        goto err;
                }
@@ -285,7 +279,7 @@ int main(int argc, char **argv)
                char *rhost = NULL;
                char *service = NULL;
 
-               if (check_user(user) != 0) {
+               if (!has_user(user)) {
                        warnx(_("User '%s' does not exist."), user);
                        goto err;
                }