Avoid calling strlen() where we can use the strspn() return value.

This commit is contained in:
ed 2015-08-03 22:07:50 +00:00
parent ce892f6643
commit 08ce46330f
2 changed files with 9 additions and 9 deletions

View File

@ -297,7 +297,7 @@ pw_group_show(int argc, char **argv, char *arg1)
};
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, GID_MAX);
else
name = arg1;
@ -360,7 +360,7 @@ pw_group_del(int argc, char **argv, char *arg1)
bool nis = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, GID_MAX);
else
name = arg1;
@ -491,7 +491,7 @@ pw_group_add(int argc, char **argv, char *arg1)
quiet = precrypted = dryrun = pretty = nis = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, GID_MAX);
else
name = arg1;
@ -577,7 +577,7 @@ pw_group_mod(int argc, char **argv, char *arg1)
quiet = pretty = dryrun = nis = precrypted = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, GID_MAX);
else
name = arg1;

View File

@ -214,7 +214,7 @@ pw_userlock(char *arg1, int mode)
if (arg1 == NULL)
errx(EX_DATAERR, "username or id required");
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, UID_MAX);
else
name = arg1;
@ -709,7 +709,7 @@ pw_user_show(int argc, char **argv, char *arg1)
bool quiet = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, UID_MAX);
else
name = arg1;
@ -793,7 +793,7 @@ pw_user_del(int argc, char **argv, char *arg1)
bool quiet = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, UID_MAX);
else
name = arg1;
@ -1124,7 +1124,7 @@ pw_user_add(int argc, char **argv, char *arg1)
err(EXIT_FAILURE, "calloc()");
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, UID_MAX);
else
name = arg1;
@ -1435,7 +1435,7 @@ pw_user_mod(int argc, char **argv, char *arg1)
edited = docreatehome = false;
if (arg1 != NULL) {
if (strspn(arg1, "0123456789") == strlen(arg1))
if (arg1[strspn(arg1, "0123456789")] == '\0')
id = pw_checkid(arg1, UID_MAX);
else
name = arg1;