]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/list.c: Use strsep2ls() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 8 Feb 2025 12:00:22 +0000 (13:00 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Sat, 7 Jun 2025 14:52:03 +0000 (16:52 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/list.c

index 27aa02565998ea41f32a27cad4905ae3ceb172b7..25735d72fc4d97b4c13a93935aaf4924cdc74bfc 100644 (file)
@@ -18,6 +18,7 @@
 #include "string/strchr/strchrcnt.h"
 #include "string/strcmp/streq.h"
 #include "string/strdup/xstrdup.h"
+#include "string/strtok/strsep2ls.h"
 
 
 /*
@@ -186,9 +187,7 @@ comma_to_list(const char *comma)
 {
        char *members;
        char **array;
-       int i;
-       char *cp;
-       char *cp2;
+       size_t  n;
 
        assert (NULL != comma);
 
@@ -203,7 +202,8 @@ comma_to_list(const char *comma)
         * n: number of delimiters + last element + NULL
         */
 
-       array = XMALLOC(strchrcnt(members, ',') + 2, char *);
+       n = strchrcnt(members, ',') + 2;
+       array = XMALLOC(n, char *);
 
        /*
         * Empty list is special - 0 members, not 1 empty member.  --marekm
@@ -215,18 +215,7 @@ comma_to_list(const char *comma)
                return array;
        }
 
-       /*
-        * Now go walk that list all over again, this time building the
-        * array of pointers.
-        */
-
-       for (cp = members, i = 0; cp != NULL; i++)
-               array[i] = strsep(&cp, ",");
-       array[i] = NULL;
-
-       /*
-        * Return the new array of pointers
-        */
+       strsep2ls(members, ",", n, array);
 
        return array;
 }