]> git.sesse.net Git - vlc/blob - src/os2/plugin.c
decoder: drain the audio output properly
[vlc] / src / os2 / plugin.c
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
6  * $Id$
7  *
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>
13  *
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.
18  *
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.
23  *
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  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_charset.h>
35 #include "modules/modules.h"
36
37 #include <sys/types.h>
38 #include <dlfcn.h>
39
40 /**
41  * Load a dynamically linked library using a system dependent method.
42  *
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.
47  */
48 int module_Load( vlc_object_t *p_this, const char *psz_file,
49                  module_handle_t *p_handle, bool lazy )
50 {
51     const int flags = lazy ? RTLD_LAZY : RTLD_NOW;
52     char *path = ToLocale( psz_file );
53
54     module_handle_t handle = dlopen( path, flags );
55     if( handle == NULL )
56     {
57         msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
58         LocaleFree( path );
59         return -1;
60     }
61     LocaleFree( path );
62     *p_handle = handle;
63     return 0;
64 }
65
66 /**
67  * CloseModule: unload a dynamic library
68  *
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
73  * \return nothing
74  */
75 void module_Unload( module_handle_t handle )
76 {
77     dlclose( handle );
78 }
79
80 /**
81  * Looks up a symbol from a dynamically loaded library
82  *
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.
86  *
87  * @param handle handle to the module
88  * @param psz_function function name
89  * @return NULL on error, or the address of the symbol
90  */
91 void *module_Lookup( module_handle_t handle, const char *psz_function )
92 {
93     return dlsym( handle, psz_function );
94 }