]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Use xastrsep2ls() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 7 Dec 2024 01:02:07 +0000 (02:02 +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/gshadow.c
lib/sgetgrent.c

index 5e7e3b14103a7a7c64f5245a0589dc713b852efe..a240d386abf3eb7c78b25fc7a3f3676e986554b4 100644 (file)
 
 #include "alloc/malloc.h"
 #include "alloc/realloc.h"
-#include "alloc/x/xmalloc.h"
 #include "defines.h"
 #include "prototypes.h"
-#include "string/strchr/strchrcnt.h"
 #include "string/strcmp/streq.h"
 #include "string/strtok/stpsep.h"
 #include "string/strtok/strsep2arr.h"
+#include "string/strtok/xastrsep2ls.h"
 
 
 static /*@null@*/FILE *shadow;
@@ -37,14 +36,12 @@ static /*@null@*/char **
 build_list(char *s)
 {
        char    **l;
-       size_t  i;
+       size_t  n;
 
-       l = XMALLOC(strchrcnt(s, ',') + 2, char *);
+       l = xastrsep2ls(s, ",", &n);
 
-       for (i = 0; s != NULL && !streq(s, ""); i++)
-               l[i] = strsep(&s, ",");
-
-       l[i] = NULL;
+       if (streq(l[n-1], ""))
+               l[n-1] = NULL;
 
        return l;
 }
index 20048502ab42e5b326dc00fe9e147f3dd39c464b..526539489efd0c3d913ee4b6220a01c261fffad0 100644 (file)
 #include <sys/types.h>
 
 #include "alloc/malloc.h"
-#include "alloc/reallocf.h"
 #include "atoi/getnum.h"
 #include "defines.h"
 #include "prototypes.h"
 #include "string/strcmp/streq.h"
 #include "string/strtok/stpsep.h"
 #include "string/strtok/strsep2arr.h"
+#include "string/strtok/astrsep2ls.h"
 
 
 /*
@@ -40,29 +40,18 @@ static char **
 list(char *s)
 {
        static char **members = NULL;
-       static size_t size = 0; /* max members + 1 */
-       size_t i;
+
+       size_t  n;
 
        free(members);
-       members = NULL;
-
-       i = 0;
-       for (;;) {
-               /* check if there is room for another pointer (to a group
-                  member name, or terminating NULL).  */
-               if (i >= size) {
-                       size = i + 100; /* at least: i + 1 */
-                       members = REALLOCF(members, size, char *);
-                       if (!members) {
-                               size = 0;
-                               return NULL;
-                       }
-               }
-               if (!s || streq(s, ""))
-                       break;
-               members[i++] = strsep(&s, ",");
-       }
-       members[i] = NULL;
+
+       members = astrsep2ls(s, ",", &n);
+       if (members == NULL)
+               return NULL;
+
+       if (streq(members[n-1], ""))
+               members[n-1] = NULL;
+
        return members;
 }