From 915f7fc02dfb6d59f406feb723fafbcffb440872 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 31 Dec 2024 23:37:39 +0100 Subject: [PATCH] src/: Simplify, using strpbrk(3) Checking a boolean (actually, a boolean-like pointer) is more readable than comparing against a length. This removes the only uses of strcspn(3) in this project. strpbrk(3) is a simpler call, even though it has a weird name. It's just like strchr(3) but searches for several characters. I'd have named it strchrs(). Signed-off-by: Alejandro Colomar --- src/useradd.c | 2 +- src/usermod.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/useradd.c b/src/useradd.c index ee52aafde..54fb0e66d 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -110,7 +110,7 @@ static const char *def_log_init = "yes"; static long def_inactive = -1; static const char *def_expire = ""; -#define VALID(s) (strcspn (s, ":\n") == strlen (s)) +#define VALID(s) (!strpbrk(s, ":\n")) static const char *user_name = ""; static const char *user_pass = "!"; diff --git a/src/usermod.c b/src/usermod.c index 7ea1a7244..49159d60f 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -93,7 +93,7 @@ #define E_SUB_GID_UPDATE 18 /* can't update the subordinate gid file */ #endif /* ENABLE_SUBIDS */ -#define VALID(s) (strcspn (s, ":\n") == strlen (s)) +#define VALID(s) (!strpbrk(s, ":\n")) /* * Global variables