]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use stpspn() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Wed, 3 Jul 2024 20:47:45 +0000 (22:47 +0200)
committerSerge Hallyn <serge@hallyn.com>
Mon, 14 Oct 2024 01:40:02 +0000 (20:40 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/fields.c
lib/getdate.y
lib/limits.c
lib/loginprompt.c
lib/nss.c
lib/setupenv.c
lib/strtoday.c

index 555f4bedf9f3bafa44d5ebdb4a0531e04623ddcc..32399fe5dd77e8abde3280e55df8dd1d37845467 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdio.h>
 
 #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);
        }
 }
index 31f1aa0fbf96a7ad6da2f2e89012b02a9cb6f794..385e55c692841fda77beff3baa0641fc036a9ae3 100644 (file)
 # undef static
 #endif
 
-#include <stdio.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <string.h>
 #include <time.h>
 
 #include "attr.h"
 #include "getdate.h"
+#include "string/strchr/stpspn.h"
 
-#include <string.h>
 
 /* 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 == '+')
        {
index 21c1635d5a9f6cf847efc290122b6a3f7cc1664f..74398bd82b5d4c368da31cf9098e55805c0511d7 100644 (file)
@@ -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;
 }
index 95e9018b2deecc969f6945146d208e2c97aa5167..cbac28ab8579febf87aa8782d7de0a6939d37299 100644 (file)
@@ -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++);
 
index 23a3683b2d92d6cdbc33662597312c61788f8b79..f0fcc026ac51d2052474bdaf6b30f408e039e43a 100644 (file)
--- 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;
index 16d8e93ece2cc7aa45cc8b10ccf1c4d2aea6578e..f49c6adefc8656e25550ddaa7d112d122c49d861 100644 (file)
@@ -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;
                }
index 2d69e74b1d8ca05f7af68dc7bf0876dbf0c724f6..db0866097198a7e9a7025182619d0ac482aa5b96 100644 (file)
@@ -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;