[pulseaudio-discuss] [PATCH v4 39/41] module: Create pa_module_exists()

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Sat Sep 21 08:11:54 PDT 2013


On Wed, 2013-09-18 at 16:17 -0500, jprvita at gmail.com wrote:
> From: João Paulo Rechi Vita <jprvita at openbossa.org>
> 
> This new function checks if a certain module name is available in the
> system.
> ---
>  src/pulsecore/module.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  src/pulsecore/module.h |  2 ++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c
> index 16582b3..bc53f07 100644
> --- a/src/pulsecore/module.c
> +++ b/src/pulsecore/module.c
> @@ -28,6 +28,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <errno.h>
> +#include <ltdl.h>
>  
>  #include <pulse/xmalloc.h>
>  #include <pulse/proplist.h>
> @@ -47,6 +48,54 @@
>  #define PA_SYMBOL_GET_N_USED "pa__get_n_used"
>  #define PA_SYMBOL_GET_DEPRECATE "pa__get_deprecated"
>  
> +bool pa_module_exists(const char *name) {
> +    const char *paths, *state = NULL;
> +    char *p, *pathname;
> +    bool result;
> +
> +    pa_assert(name);
> +
> +    if (name[0] == PA_PATH_SEP_CHAR) {
> +        result = access(name, F_OK) == 0 ? true : false;
> +        pa_log_debug("Checking for existence of '%s': %s", name, result ? "success" : "failure");
> +        if (result)
> +            return true;
> +    }
> +
> +    if (!(paths = lt_dlgetsearchpath()))
> +        return false;
> +
> +    /* strip .so from the end of name, if present */
> +    p = rindex(name, '.');
> +    if (p && pa_streq(p, ".so"))

Use PA_SOEXT instead of hardcoding ".so".

> +        p[0] = 0;
> +
> +    while ((p = pa_split(paths, ":", &state))) {
> +        pathname = pa_sprintf_malloc("%s" PA_PATH_SEP "%s.so", p, name);

Use PA_SOEXT also here...

> +        result = access(pathname, F_OK) == 0 ? true : false;
> +        pa_log_debug("Checking for existence of '%s': %s", pathname, result ? "success" : "failure");
> +        pa_xfree(pathname);
> +        pa_xfree(p);
> +        if (result)
> +            return true;
> +    }
> +
> +    state = NULL;
> +    if (PA_UNLIKELY(pa_run_from_build_tree())) {
> +        while ((p = pa_split(paths, ":", &state))) {
> +            pathname = pa_sprintf_malloc("%s" PA_PATH_SEP ".libs" PA_PATH_SEP "%s.so", p, name);

...and here.

-- 
Tanu



More information about the pulseaudio-discuss mailing list