1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
5 * Copyright (C) 2012 KO Myung-Hun
8 * Authors: Sam Hocevar <sam@zoy.org>
9 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
10 * Hans-Peter Jansen <hpj@urpla.net>
11 * Gildas Bazin <gbazin@videolan.org>
12 * KO Myung-Hun <komh@chollian.net>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation; either version 2.1 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_charset.h>
35 #include "modules/modules.h"
37 #include <sys/types.h>
41 * Load a dynamically linked library using a system dependent method.
43 * \param p_this vlc object
44 * \param psz_file library file
45 * \param p_handle the module handle returned
46 * \return 0 on success as well as the module handle.
48 int module_Load( vlc_object_t *p_this, const char *psz_file,
49 module_handle_t *p_handle, bool lazy )
51 const int flags = lazy ? RTLD_LAZY : RTLD_NOW;
52 char *path = ToLocale( psz_file );
54 module_handle_t handle = dlopen( path, flags );
57 msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
67 * CloseModule: unload a dynamic library
69 * This function unloads a previously opened dynamically linked library
70 * using a system dependent method. No return value is taken in consideration,
71 * since some libraries sometimes refuse to close properly.
72 * \param handle handle of the library
75 void module_Unload( module_handle_t handle )
81 * Looks up a symbol from a dynamically loaded library
83 * This function queries a loaded library for a symbol specified in a
84 * string, and returns a pointer to it. We don't check for dlerror() or
85 * similar functions, since we want a non-NULL symbol anyway.
87 * @param handle handle to the module
88 * @param psz_function function name
89 * @return NULL on error, or the address of the symbol
91 void *module_Lookup( module_handle_t handle, const char *psz_function )
93 return dlsym( handle, psz_function );