1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
6 * Authors: Sam Hocevar <sam@zoy.org>
7 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
8 * Hans-Peter Jansen <hpj@urpla.net>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
31 #include <vlc_common.h>
32 #include "modules/modules.h"
34 #include <sys/types.h>
37 #ifdef HAVE_VALGRIND_VALGRIND_H
38 # include <valgrind/valgrind.h>
41 void *vlc_dlopen(const char *path
, bool lazy
)
43 #if defined (RTLD_NOW)
44 const int flags
= lazy
? RTLD_LAZY
: RTLD_NOW
;
45 #elif defined (DL_LAZY)
46 const int flags
= DL_LAZY
;
52 return dlopen (path
, flags
);
55 int vlc_dlclose(void *handle
)
57 #if !defined(__SANITIZE_ADDRESS__)
58 #ifdef HAVE_VALGRIND_VALGRIND_H
59 if( RUNNING_ON_VALGRIND
> 0 )
60 return 0; /* do not dlclose() so that we get proper stack traces */
62 int err
= dlclose( handle
);
71 void *vlc_dlsym(void *handle
, const char *name
)
73 return dlsym(handle
, name
);
76 char *vlc_dlerror(void)
78 const char *errmsg
= dlerror();
79 /* XXX: This is not thread-safe at all. POSIX is helpless here. */
80 return (errmsg
!= NULL
) ? strdup(errmsg
) : NULL
;