From: Alejandro Colomar Date: Sat, 7 Dec 2024 01:02:07 +0000 (+0100) Subject: lib/: Use xastrsep2ls() instead of its pattern X-Git-Tag: 4.18.0-rc1~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71ea4998d21457179f4256bfa04a409df4e86637;p=thirdparty%2Fshadow.git lib/: Use xastrsep2ls() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/gshadow.c b/lib/gshadow.c index 5e7e3b141..a240d386a 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -20,13 +20,12 @@ #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; } diff --git a/lib/sgetgrent.c b/lib/sgetgrent.c index 20048502a..526539489 100644 --- a/lib/sgetgrent.c +++ b/lib/sgetgrent.c @@ -18,13 +18,13 @@ #include #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; }