chromecast: rework demux pacing
[vlc.git] / src / os2 / plugin.c
blobc57180cfa7e247a74bf95d0929f9569b939f5ed9
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$
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 *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
33 #include <string.h>
35 #include <vlc_common.h>
36 #include <vlc_charset.h>
37 #include "modules/modules.h"
39 #include <sys/types.h>
40 #include <dlfcn.h>
42 /**
43 * Load a dynamically linked library using a system dependent method.
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.
50 int module_Load( vlc_object_t *p_this, const char *psz_file,
51 module_handle_t *p_handle, bool lazy )
53 const int flags = lazy ? RTLD_LAZY : RTLD_NOW;
54 char *path = ToLocaleDup( psz_file );
56 module_handle_t handle = dlopen( path, flags );
57 if( handle == NULL )
59 msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
60 free( path );
61 return -1;
63 free( path );
64 *p_handle = handle;
65 return 0;
68 /**
69 * CloseModule: unload a dynamic library
71 * This function unloads a previously opened dynamically linked library
72 * using a system dependent method. No return value is taken in consideration,
73 * since some libraries sometimes refuse to close properly.
74 * \param handle handle of the library
75 * \return nothing
77 void module_Unload( module_handle_t handle )
79 dlclose( handle );
82 /**
83 * Looks up a symbol from a dynamically loaded library
85 * This function queries a loaded library for a symbol specified in a
86 * string, and returns a pointer to it. We don't check for dlerror() or
87 * similar functions, since we want a non-NULL symbol anyway.
89 * @param handle handle to the module
90 * @param psz_function function name
91 * @return NULL on error, or the address of the symbol
93 void *module_Lookup( module_handle_t handle, const char *psz_function )
95 char buf[strlen(psz_function) + 2];
96 buf[0] = '_';
97 strcpy(buf + 1, psz_function);
98 return dlsym( handle, buf );