src/pulsecore/core-util.c | 30 +++++++++++++++++++++++------- src/pulsecore/core-util.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-)
New commits: commit fbf95fa5e97d181ad20ca781cb021cd3fe2fc7d9 Author: Hajime Fujita <crisp.fuj...@nifty.com> Date: Sun Nov 6 12:53:57 2016 -0600 core-util: do in-place search in pa_str_in_list_spaces Reviewed-by: Anton Lundin <gla...@acc.umu.se> diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 9d571b8..cd1c96d 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -3022,19 +3022,16 @@ bool pa_str_in_list(const char *haystack, const char *delimiters, const char *ne /* Checks a whitespace-separated list of words in haystack for needle */ bool pa_str_in_list_spaces(const char *haystack, const char *needle) { - char *s; + const char *s; + int n; const char *state = NULL; if (!haystack || !needle) return false; - while ((s = pa_split_spaces(haystack, &state))) { - if (pa_streq(needle, s)) { - pa_xfree(s); + while ((s = pa_split_spaces_in_place(haystack, &n, &state))) { + if (pa_strneq(needle, s, n)) return true; - } - - pa_xfree(s); } return false; commit 0e70593a8ddb7e53af30bdc055c0faecce2937e9 Author: Hajime Fujita <crisp.fuj...@nifty.com> Date: Sun Nov 6 12:53:56 2016 -0600 core-util: add pa_split_space_in_place function Reviewed-by: Anton Lundin <gla...@acc.umu.se> diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index f2999b2..9d571b8 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1121,6 +1121,25 @@ char *pa_split_spaces(const char *c, const char **state) { return pa_xstrndup(current, l); } +/* Similar to pa_split_spaces, except this returns a string in-place. + Returned string is generally not NULL-terminated. + See pa_split_in_place(). */ +const char *pa_split_spaces_in_place(const char *c, int *n, const char **state) { + const char *current = *state ? *state : c; + size_t l; + + if (!*current || *c == 0) + return NULL; + + current += strspn(current, WHITESPACE); + l = strcspn(current, WHITESPACE); + + *state = current+l; + + *n = l; + return current; +} + PA_STATIC_TLS_DECLARE(signame, pa_xfree); /* Return the name of an UNIX signal. Similar to Solaris sig2str() */ diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index be023a8..e28b6aa 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -112,6 +112,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); +const char *pa_split_spaces_in_place(const char *c, int *n, const char **state); char *pa_strip_nl(char *s); char *pa_strip(char *s); commit 551f4ec43261f65a0f33466db2c16a5805c3cde2 Author: Hajime Fujita <crisp.fuj...@nifty.com> Date: Sun Nov 6 12:53:55 2016 -0600 core-util: add pa_strneq macro This macro compares if the given two strings, with the maximum length of n, are equal. Useful for strings that are not NULL-terminated. Reviewed-by: Anton Lundin <gla...@acc.umu.se> diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 8847528..be023a8 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -219,6 +219,7 @@ void pa_unset_env_recorded(void); bool pa_in_system_mode(void); #define pa_streq(a,b) (!strcmp((a),(b))) +#define pa_strneq(a,b,n) (!strncmp((a),(b),(n))) /* Like pa_streq, but does not blow up on NULL pointers. */ static inline bool pa_safe_streq(const char *a, const char *b) { _______________________________________________ pulseaudio-commits mailing list pulseaudio-commits@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits