#include "string/strchr/strchrcnt.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
+#include "string/strtok/strsep2ls.h"
/*
{
char *members;
char **array;
- int i;
- char *cp;
- char *cp2;
+ size_t n;
assert (NULL != comma);
* n: number of delimiters + last element + NULL
*/
- array = XMALLOC(strchrcnt(members, ',') + 2, char *);
+ n = strchrcnt(members, ',') + 2;
+ array = XMALLOC(n, char *);
/*
* Empty list is special - 0 members, not 1 empty member. --marekm
return array;
}
- /*
- * Now go walk that list all over again, this time building the
- * array of pointers.
- */
-
- for (cp = members, i = 0; cp != NULL; i++)
- array[i] = strsep(&cp, ",");
- array[i] = NULL;
-
- /*
- * Return the new array of pointers
- */
+ strsep2ls(members, ",", n, array);
return array;
}