Skip to content

Commit 71ea499

Browse files
lib/: Use xastrsep2ls() instead of its pattern
Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 422a5e9 commit 71ea499

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

lib/gshadow.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020

2121
#include "alloc/malloc.h"
2222
#include "alloc/realloc.h"
23-
#include "alloc/x/xmalloc.h"
2423
#include "defines.h"
2524
#include "prototypes.h"
26-
#include "string/strchr/strchrcnt.h"
2725
#include "string/strcmp/streq.h"
2826
#include "string/strtok/stpsep.h"
2927
#include "string/strtok/strsep2arr.h"
28+
#include "string/strtok/xastrsep2ls.h"
3029

3130

3231
static /*@null@*/FILE *shadow;
@@ -37,14 +36,12 @@ static /*@null@*/char **
3736
build_list(char *s)
3837
{
3938
char **l;
40-
size_t i;
39+
size_t n;
4140

42-
l = XMALLOC(strchrcnt(s, ',') + 2, char *);
41+
l = xastrsep2ls(s, ",", &n);
4342

44-
for (i = 0; s != NULL && !streq(s, ""); i++)
45-
l[i] = strsep(&s, ",");
46-
47-
l[i] = NULL;
43+
if (streq(l[n-1], ""))
44+
l[n-1] = NULL;
4845

4946
return l;
5047
}

lib/sgetgrent.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include <sys/types.h>
1919

2020
#include "alloc/malloc.h"
21-
#include "alloc/reallocf.h"
2221
#include "atoi/getnum.h"
2322
#include "defines.h"
2423
#include "prototypes.h"
2524
#include "string/strcmp/streq.h"
2625
#include "string/strtok/stpsep.h"
2726
#include "string/strtok/strsep2arr.h"
27+
#include "string/strtok/astrsep2ls.h"
2828

2929

3030
/*
@@ -40,29 +40,18 @@ static char **
4040
list(char *s)
4141
{
4242
static char **members = NULL;
43-
static size_t size = 0; /* max members + 1 */
44-
size_t i;
43+
44+
size_t n;
4545

4646
free(members);
47-
members = NULL;
48-
49-
i = 0;
50-
for (;;) {
51-
/* check if there is room for another pointer (to a group
52-
member name, or terminating NULL). */
53-
if (i >= size) {
54-
size = i + 100; /* at least: i + 1 */
55-
members = REALLOCF(members, size, char *);
56-
if (!members) {
57-
size = 0;
58-
return NULL;
59-
}
60-
}
61-
if (!s || streq(s, ""))
62-
break;
63-
members[i++] = strsep(&s, ",");
64-
}
65-
members[i] = NULL;
47+
48+
members = astrsep2ls(s, ",", &n);
49+
if (members == NULL)
50+
return NULL;
51+
52+
if (streq(members[n-1], ""))
53+
members[n-1] = NULL;
54+
6655
return members;
6756
}
6857

0 commit comments

Comments
 (0)