core-util: implement pa_split_spaces_strv()

This commit is contained in:
Lennart Poettering 2009-06-17 03:13:32 +02:00
parent c5dbf754b5
commit 7fa05bea7e
2 changed files with 26 additions and 0 deletions

View file

@ -2744,3 +2744,27 @@ void pa_xfreev(void**a) {
pa_xfree(a);
}
char **pa_split_spaces_strv(const char *s) {
char **t, *e;
unsigned i = 0, n = 8;
const char *state = NULL;
t = pa_xnew(char*, n);
while ((e = pa_split_spaces(s, &state))) {
t[i++] = e;
if (i >= n) {
n *= 2;
t = pa_xrenew(char*, t, n);
}
}
if (i <= 0) {
pa_xfree(t);
return NULL;
}
t[i] = NULL;
return t;
}

View file

@ -235,4 +235,6 @@ static inline void pa_xstrfreev(char **a) {
pa_xfreev((void**) a);
}
char **pa_split_spaces_strv(const char *s);
#endif