From 7fa05bea7e9980243cf58902b9d42e995d1a18bf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jun 2009 03:13:32 +0200 Subject: core-util: implement pa_split_spaces_strv() --- src/pulsecore/core-util.c | 24 ++++++++++++++++++++++++ src/pulsecore/core-util.h | 2 ++ 2 files changed, 26 insertions(+) (limited to 'src/pulsecore') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 0b64edba..e39adb12 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -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; +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 5a12ad3f..d88b7cbb 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -235,4 +235,6 @@ static inline void pa_xstrfreev(char **a) { pa_xfreev((void**) a); } +char **pa_split_spaces_strv(const char *s); + #endif -- cgit