From af93603e52d56fdd6246a038139a5d0e83a5c6a2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 20 Feb 2024 10:37:02 +0100 Subject: [PATCH] lastlog2: convert check_user() to boolean-like macro Let's make simple and stupid. Signed-off-by: Karel Zak --- misc-utils/lastlog2.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/misc-utils/lastlog2.c b/misc-utils/lastlog2.c index 91bb98caf..4029f5e48 100644 --- a/misc-utils/lastlog2.c +++ b/misc-utils/lastlog2.c @@ -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; } -- 2.47.3