Skip to content

Commit

Permalink
src/: Invert logic to improve readability
Browse files Browse the repository at this point in the history
And remove the (now) redundant comments.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Sep 1, 2024
1 parent 1c127bd commit 0663c91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
19 changes: 8 additions & 11 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,17 @@ static void grp_update (void)
* check_new_name() insures that the new name doesn't contain any
* illegal characters.
*/
static void check_new_name (void)
static void
check_new_name(void)
{
if (is_valid_group_name (group_name)) {
return;
}

/*
* All invalid group names land here.
*/
if (!is_valid_group_name(group_name)) {
fprintf(stderr, _("%s: '%s' is not a valid group name\n"),
Prog, group_name);

fprintf (stderr, _("%s: '%s' is not a valid group name\n"),
Prog, group_name);
exit(E_BAD_ARG);
}

exit (E_BAD_ARG);
return;
}

/*
Expand Down
36 changes: 15 additions & 21 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ static void check_new_gid (void)
* check_new_name() insures that the new name does not exist already.
* You can't have the same name twice, period.
*/
static void check_new_name (void)
static void
check_new_name(void)
{
/*
* Make sure they are actually changing the name.
Expand All @@ -361,29 +362,22 @@ static void check_new_name (void)
return;
}

if (is_valid_group_name (group_newname)) {

/*
* If the entry is found, too bad.
*/
/* local, no need for xgetgrnam */
if (prefix_getgrnam (group_newname) != NULL) {
fprintf (stderr,
_("%s: group '%s' already exists\n"),
Prog, group_newname);
exit (E_NAME_IN_USE);
}
return;
if (!is_valid_group_name(group_newname)) {
fprintf(stderr,
_("%s: invalid group name '%s'\n"),
Prog, group_newname);
exit(E_BAD_ARG);
}

/*
* All invalid group names land here.
*/
/* local, no need for xgetgrnam */
if (prefix_getgrnam(group_newname) != NULL) {
fprintf(stderr,
_("%s: group '%s' already exists\n"),
Prog, group_newname);
exit(E_NAME_IN_USE);
}

fprintf (stderr,
_("%s: invalid group name '%s'\n"),
Prog, group_newname);
exit (E_BAD_ARG);
return;
}

/*
Expand Down

0 comments on commit 0663c91

Please sign in to comment.