]> code.delx.au - pulseaudio/commitdiff
core-util: implement pa_split_spaces_strv()
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2009 01:13:32 +0000 (03:13 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Jun 2009 01:13:32 +0000 (03:13 +0200)
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index 0b64edbab88a9c136af24a580dde345c7abd02ae..e39adb121caa95575ccee4dc6a3cb3e895c190f8 100644 (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;
+}
index 5a12ad3fe9f5958f381788a9aa4858d0be821366..d88b7cbbb896fc503d0501996489111198fd0282 100644 (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