Skip to content

Commit

Permalink
src/: Simplify, using strpbrk(3)
Browse files Browse the repository at this point in the history
Comparing against NULL 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>
  • Loading branch information
alejandro-colomar committed Dec 31, 2024
1 parent 2bbe1af commit 878792c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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") == NULL)

static const char *user_name = "";
static const char *user_pass = "!";
Expand Down
2 changes: 1 addition & 1 deletion src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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") == NULL)

/*
* Global variables
Expand Down

0 comments on commit 878792c

Please sign in to comment.