]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/: Simplify, using strpbrk(3)
authorAlejandro Colomar <alx@kernel.org>
Tue, 31 Dec 2024 22:37:39 +0000 (23:37 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 27 May 2025 01:04:27 +0000 (20:04 -0500)
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 <alx@kernel.org>
src/useradd.c
src/usermod.c

index 258a6cbbba33a809ff7ce31089325b1511309070..9180d242922280469524f57843000a21c4083449 100644 (file)
@@ -111,7 +111,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 = "!";
index b4cf2e705e699d917f770b9577cb49aa08da8436..e886a1531eab6332be1de8de43946f44349675fc 100644 (file)
@@ -94,7 +94,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