File tree Expand file tree Collapse file tree 2 files changed +16
-30
lines changed Expand file tree Collapse file tree 2 files changed +16
-30
lines changed Original file line number Diff line number Diff line change 20
20
21
21
#include "alloc/malloc.h"
22
22
#include "alloc/realloc.h"
23
- #include "alloc/x/xmalloc.h"
24
23
#include "defines.h"
25
24
#include "prototypes.h"
26
- #include "string/strchr/strchrcnt.h"
27
25
#include "string/strcmp/streq.h"
28
26
#include "string/strtok/stpsep.h"
29
27
#include "string/strtok/strsep2arr.h"
28
+ #include "string/strtok/xastrsep2ls.h"
30
29
31
30
32
31
static /*@null@*/ FILE * shadow ;
@@ -37,14 +36,12 @@ static /*@null@*/char **
37
36
build_list (char * s )
38
37
{
39
38
char * * l ;
40
- size_t i ;
39
+ size_t n ;
41
40
42
- l = XMALLOC ( strchrcnt ( s , ',' ) + 2 , char * );
41
+ l = xastrsep2ls ( s , "," , & n );
43
42
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 ;
48
45
49
46
return l ;
50
47
}
Original file line number Diff line number Diff line change 18
18
#include <sys/types.h>
19
19
20
20
#include "alloc/malloc.h"
21
- #include "alloc/reallocf.h"
22
21
#include "atoi/getnum.h"
23
22
#include "defines.h"
24
23
#include "prototypes.h"
25
24
#include "string/strcmp/streq.h"
26
25
#include "string/strtok/stpsep.h"
27
26
#include "string/strtok/strsep2arr.h"
27
+ #include "string/strtok/astrsep2ls.h"
28
28
29
29
30
30
/*
@@ -40,29 +40,18 @@ static char **
40
40
list (char * s )
41
41
{
42
42
static char * * members = NULL ;
43
- static size_t size = 0 ; /* max members + 1 */
44
- size_t i ;
43
+
44
+ size_t n ;
45
45
46
46
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
+
66
55
return members ;
67
56
}
68
57
You can’t perform that action at this time.
0 commit comments