Skip to content

Commit

Permalink
lib/: Use xastrsep2ls() instead of its pattern
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Jan 10, 2025
1 parent 5f22734 commit 729949b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
13 changes: 5 additions & 8 deletions lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
33 changes: 11 additions & 22 deletions lib/sgetgrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include <string.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"


/*
Expand All @@ -39,29 +39,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;
}

Expand Down

0 comments on commit 729949b

Please sign in to comment.