]> git.sesse.net Git - vlc/blob - src/posix/plugin.c
Useless include
[vlc] / src / posix / plugin.c
1 /*****************************************************************************
2  * os.c : Low-level dynamic library handling
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
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>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
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 General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_charset.h>
33 #include "modules/modules.h"
34
35 #include <sys/types.h>
36 #include <dlfcn.h>
37
38 #ifdef HAVE_VALGRIND_VALGRIND_H
39 # include <valgrind/valgrind.h>
40 #endif
41
42 /**
43  * Load a dynamically linked library using a system dependent method.
44  *
45  * \param p_this vlc object
46  * \param psz_file library file
47  * \param p_handle the module handle returned
48  * \return 0 on success as well as the module handle.
49  */
50 int module_Load( vlc_object_t *p_this, const char *psz_file,
51                  module_handle_t *p_handle, bool lazy )
52 {
53 #if defined (RTLD_NOW)
54     const int flags = lazy ? RTLD_LAZY : RTLD_NOW;
55 #elif defined (DL_LAZY)
56     const int flags = DL_LAZY;
57 #else
58     const int flags = 0;
59 #endif
60     char *path = ToLocale( psz_file );
61
62     module_handle_t handle = dlopen( path, flags );
63     if( handle == NULL )
64     {
65         msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
66         LocaleFree( path );
67         return -1;
68     }
69     LocaleFree( path );
70     *p_handle = handle;
71     return 0;
72 }
73
74 /**
75  * CloseModule: unload a dynamic library
76  *
77  * This function unloads a previously opened dynamically linked library
78  * using a system dependent method. No return value is taken in consideration,
79  * since some libraries sometimes refuse to close properly.
80  * \param handle handle of the library
81  * \return nothing
82  */
83 void module_Unload( module_handle_t handle )
84 {
85 #ifdef HAVE_VALGRIND_VALGRIND_H
86     if( RUNNING_ON_VALGRIND > 0 )
87         return; /* do not dlclose() so that we get proper stack traces */
88 #endif
89     dlclose( handle );
90 }
91
92 /**
93  * Looks up a symbol from a dynamically loaded library
94  *
95  * This function queries a loaded library for a symbol specified in a
96  * string, and returns a pointer to it. We don't check for dlerror() or
97  * similar functions, since we want a non-NULL symbol anyway.
98  *
99  * @param handle handle to the module
100  * @param psz_function function name
101  * @return NULL on error, or the address of the symbol
102  */
103 void *module_Lookup( module_handle_t handle, const char *psz_function )
104 {
105     return dlsym( handle, psz_function );
106 }