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