[libbluray-devel] Improve dlopen on OSX

Petri Hintukainen phintuka at users.sourceforge.net
Sun Sep 2 21:34:49 CEST 2012


On ke, 2012-08-29 at 16:42 +0200, Jean-Baptiste Kempf wrote:
> libbluray | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Wed Aug 29 16:39:48 2012 +0200| [bbc5a574b1835e90f8ecc40a42cb91c14b40c034] | committer: Jean-Baptiste Kempf
> 
> Improve dlopen on OSX
> 
> It will search some common paths when dlopening libraries
> 
> > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=bbc5a574b1835e90f8ecc40a42cb91c14b40c034
> ---
> 
>  src/file/dl_posix.c |   78 ++++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 53 insertions(+), 25 deletions(-)
> 
> diff --git a/src/file/dl_posix.c b/src/file/dl_posix.c
> index 57ab232..76998dc 100644
> --- a/src/file/dl_posix.c
> +++ b/src/file/dl_posix.c
[...]
>+void   *dl_dlopen  ( const char* path, const char *version )
>+{
>+    char *name;
>+    void *dll;
>+    int i;
>+
> +#if defined(__APPLE__)
> +    static const char ext[] = ".dylib";
> +    /*
> +      Search for the library in several locations:
> +       ""               - default search path (including DYLD_LIBRARY_PATH)
> +       @loader_path     - location of current library/binary (ex. libbluray.dylib)
> +       @executable_path - location of running binary (ex. /Applications/Some.app/Contents/MacOS)
> +       @rpath           - search rpaths of running binary (man install_name_path)
> +    */
> +    static const char *search_paths[] = {"", "@loader_path/lib/", "@loader_path/", "@executable_path/",
> +                                         "@executable_path/lib/", "@executable_path/../lib/",
> +                                         "@executable_path/../Resources/", "@rpath/", NULL};
> +    version = NULL;
> +#elif defined(_WIN32)
> +    static const char ext[] = ".dll";
> +    static const char *search_paths[] = {"", NULL};
> +    version = NULL;
> +#else
> +    static const char ext[] = ".so";
> +    static const char *search_paths[] = {"", NULL};
> +#endif
> +
> +    for (i = 1 ; search_paths[i] ; ++i) {

Should this be
  for (i = 0; ...

(search_paths[1] == NULL for all but OS X...)

> +        if (version) {
> +            name = str_printf("%s%s%s.%s", search_paths[i], path, ext, version);
> +        } else {
> +            name = str_printf("%s%s%s", search_paths[i], path, ext);
> +        }
> +
> +        fprintf (stderr, "Attempting to open %s\n", name);
> +
> +        dll = _dl_dlopen (name);
> +        X_FREE(name);
> +        if (dll) {
> +            return dll;
> +        }
> +    }
> +
> +    return NULL;
> +}
> +
>  void   *dl_dlsym   ( void* handle, const char* symbol )
>  {
>  #if defined(_WIN32)
> 
> _______________________________________________
> libbluray-devel mailing list
> libbluray-devel at videolan.org
> http://mailman.videolan.org/listinfo/libbluray-devel




More information about the libbluray-devel mailing list