From: Alejandro Colomar Date: Wed, 3 Jul 2024 20:47:45 +0000 (+0200) Subject: lib/, src/: Use stpspn() instead of its pattern X-Git-Tag: 4.17.0-rc1~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f45adadd28993460d21a8e019f9e61c0c9deb308;p=thirdparty%2Fshadow.git lib/, src/: Use stpspn() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/fields.c b/lib/fields.c index 555f4bedf..32399fe5d 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -16,6 +16,7 @@ #include #include "prototypes.h" +#include "string/strchr/stpspn.h" #include "string/strchr/strrspn.h" #include "string/strtok/stpsep.h" @@ -91,12 +92,7 @@ void change_field (char *buf, size_t maxsize, const char *prompt) * entering a space. --marekm */ stpcpy(strrspn(newf, " \t\n"), ""); - - cp = newf; - while (isspace (*cp)) { - cp++; - } - + cp = stpspn(newf, " \t"); strcpy (buf, cp); } } diff --git a/lib/getdate.y b/lib/getdate.y index 31f1aa0fb..385e55c69 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -24,14 +24,15 @@ # undef static #endif -#include #include +#include +#include #include #include "attr.h" #include "getdate.h" +#include "string/strchr/stpspn.h" -#include /* Some old versions of bison generate parsers that use bcopy. That loses on systems that don't provide the function, so we have @@ -746,8 +747,7 @@ yylex (void) for (;;) { - while (isspace (*yyInput)) - yyInput++; + yyInput = stpspn(yyInput, " \t"); if (isdigit (c = *yyInput) || c == '-' || c == '+') { diff --git a/lib/limits.c b/lib/limits.c index 21c1635d5..74398bd82 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -36,6 +36,7 @@ #include "atoi/str2i/str2s.h" #include "atoi/str2i/str2u.h" #include "string/memset/memzero.h" +#include "string/strchr/stpspn.h" #include "typetraits.h" @@ -185,11 +186,7 @@ static int do_user_limits (const char *buf, const char *name) int retval = 0; bool reported = false; - pp = buf; - /* Skip leading whitespace. */ - while ((' ' == *pp) || ('\t' == *pp)) { - pp++; - } + pp = stpspn(buf, " \t"); /* The special limit string "-" results in no limit for all known * limits. @@ -313,12 +310,7 @@ static int do_user_limits (const char *buf, const char *name) * So, let's skip all digits, "-" and our limited set of * whitespace. */ - while ( isdigit (*pp) - || ('-' == *pp) - || (' ' == *pp) - || ('\t' ==*pp)) { - pp++; - } + pp = stpspn(pp, "0123456789- \t"); } return retval; } diff --git a/lib/loginprompt.c b/lib/loginprompt.c index 95e9018b2..cbac28ab8 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -20,6 +20,7 @@ #include "getdef.h" #include "prototypes.h" #include "string/memset/memzero.h" +#include "string/strchr/stpspn.h" #include "string/strtok/stpsep.h" @@ -93,7 +94,7 @@ void login_prompt (char *name, int namesize) * Then copy the rest (up to the end) into the username. */ - for (cp = buf; *cp == ' ' || *cp == '\t'; cp++); + cp = stpspn(buf, " \t"); for (i = 0; i < namesize - 1 && *cp != '\0'; name[i++] = *cp++); diff --git a/lib/nss.c b/lib/nss.c index 23a3683b2..f0fcc026a 100644 --- a/lib/nss.c +++ b/lib/nss.c @@ -16,6 +16,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strtok/stpsep.h" +#include "string/strchr/stpspn.h" #define NSSWITCH "/etc/nsswitch.conf" @@ -84,8 +85,7 @@ nss_init(const char *nsswitch_path) { if (strncasecmp(line, "subid:", 6) != 0) continue; p = &line[6]; - while (isspace(*p)) - p++; + p = stpspn(p, " \t\n"); if (*p != '\0') break; p = NULL; diff --git a/lib/setupenv.c b/lib/setupenv.c index 16d8e93ec..f49c6adef 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -27,6 +27,7 @@ #include "getdef.h" #include "shadowlog.h" #include "string/sprintf/xasprintf.h" +#include "string/strchr/stpspn.h" #include "string/strdup/xstrdup.h" #include "string/strtok/stpsep.h" @@ -58,9 +59,7 @@ static void read_env_file (const char *filename) cp = buf; /* ignore whitespace and comments */ - while (isspace (*cp)) { - cp++; - } + cp = stpspn(cp, " \t"); if (('\0' == *cp) || ('#' == *cp)) { continue; } diff --git a/lib/strtoday.c b/lib/strtoday.c index 2d69e74b1..db0866097 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -14,8 +14,9 @@ #ident "$Id$" #include "atoi/str2i/str2s.h" -#include "prototypes.h" #include "getdate.h" +#include "prototypes.h" +#include "string/strchr/stpspn.h" /* @@ -53,9 +54,7 @@ long strtoday (const char *str) if ('-' == *s) { s++; } - while (' ' == *s) { - s++; - } + s = stpspn(s, " "); while (isnum && ('\0' != *s)) { if (!isdigit (*s)) { isnum = false;