diff mbox

[pulseaudio-discuss,RFC,1/4] Integrate UCM basic functions into alsa card module

Message ID 1339566767.5228.22.camel@localhost
State New
Headers show

Commit Message

Arun Raghavan June 13, 2012, 5:52 a.m. UTC
Hi,

On Mon, 2012-06-11 at 18:28 +0800, Feng Wei wrote:
[snip]
> >> +static int ucm_port_contain(const char *port_name, const char *dev_name) {
> >> +    int ret=0;
> >> +    char *r;
> >> +    const char *state=NULL;
> >> +
> >> +    if (!port_name || !dev_name)
> >> +        return FALSE;
> >> +
> >> +    while ((r = pa_split(port_name, "+", &state))) {
> >> +        if (!strcmp(r, dev_name)) {
> >> +            pa_xfree(r);
> >> +            ret = 1;
> >> +            break;
> >> +        }
> >> +        pa_xfree(r);
> >> +    }
> >> +    return ret;
> >> +}
> >
> > Better to use strstr() here. Avoids some unnecessary allocation +
> > deallocation.
> Is it possible that we have sub string matching in error?

I'm attaching a patch snippet of something that might be useful instead.
Untested, but should work -- if it looks fine, I can commit this.

One comment that I missed, I think -- I see that you've called
structures pa_alsa_ucm_* and functions pa_ucm_*. Could you make them all
pa_alsa_ucm_*?

Thanks for all the efforts,
Arun

Comments

Feng Wei June 13, 2012, 8:20 a.m. UTC | #1
Hi Arun,
The patch works well in my test, I have it called in ucm.
And I have committed some new patches at
http://git.linaro.org/gitweb?p=people/weifeng/pulseaudio.git;a=shortlog,
to make the code better.

2012/6/13 Arun Raghavan <arun.raghavan@collabora.co.uk>:
> Hi,
>
> On Mon, 2012-06-11 at 18:28 +0800, Feng Wei wrote:
> [snip]
>> >> +static int ucm_port_contain(const char *port_name, const char *dev_name) {
>> >> +    int ret=0;
>> >> +    char *r;
>> >> +    const char *state=NULL;
>> >> +
>> >> +    if (!port_name || !dev_name)
>> >> +        return FALSE;
>> >> +
>> >> +    while ((r = pa_split(port_name, "+", &state))) {
>> >> +        if (!strcmp(r, dev_name)) {
>> >> +            pa_xfree(r);
>> >> +            ret = 1;
>> >> +            break;
>> >> +        }
>> >> +        pa_xfree(r);
>> >> +    }
>> >> +    return ret;
>> >> +}
>> >
>> > Better to use strstr() here. Avoids some unnecessary allocation +
>> > deallocation.
>> Is it possible that we have sub string matching in error?
>
> I'm attaching a patch snippet of something that might be useful instead.
> Untested, but should work -- if it looks fine, I can commit this.
>
> One comment that I missed, I think -- I see that you've called
> structures pa_alsa_ucm_* and functions pa_ucm_*. Could you make them all
> pa_alsa_ucm_*?
>
> Thanks for all the efforts,
> Arun
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
>
diff mbox

Patch

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index dc9412f..e2e1ec7 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -947,6 +947,27 @@  char *pa_split(const char *c, const char *delimiter, const char**state) {
     return pa_xstrndup(current, l);
 }
 
+/* Split the specified string wherever one of the strings in delimiter
+ * occurs. Each time it is called returns a pointer to the substring within the
+ * string and the length in n. The variable state points to, should be
+ * initialized to NULL before the first call. */
+const char *pa_split_in_place(const char *c, const char *delimiter, int *n, const char**state) {
+    const char *current = *state ? *state : c;
+    size_t l;
+
+    if (!*current)
+        return NULL;
+
+    l = strcspn(current, delimiter);
+    *state = current+l;
+
+    if (**state)
+        (*state)++;
+
+    *n = l;
+    return current;
+}
+
 /* Split a string into words. Otherwise similar to pa_split(). */
 char *pa_split_spaces(const char *c, const char **state) {
     const char *current = *state ? *state : c;
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 4a1c096..a3c2247 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -100,6 +100,7 @@  static inline const char *pa_strna(const char *x) {
 }
 
 char *pa_split(const char *c, const char*delimiters, const char **state);
+const char *pa_split_in_place(const char *c, const char*delimiters, int *n, const char **state);
 char *pa_split_spaces(const char *c, const char **state);
 
 char *pa_strip_nl(char *s);