packetizer: hxxx: fix DirectTV extraction
[vlc.git] / src / posix / plugin.c
blob4f30da184e335b0f7a96d078191097aa0b3a762c
1 /*****************************************************************************
2 * plugin.c : Low-level dynamic library handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
5 * $Id$
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 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include "modules/modules.h"
34 #include <sys/types.h>
35 #include <dlfcn.h>
37 #ifdef HAVE_VALGRIND_VALGRIND_H
38 # include <valgrind/valgrind.h>
39 #endif
41 /**
42 * Load a dynamically linked library using a system dependent method.
44 * \param p_this vlc object
45 * \param path library file
46 * \param p_handle the module handle returned
47 * \return 0 on success as well as the module handle.
49 int module_Load (vlc_object_t *p_this, const char *path,
50 module_handle_t *p_handle, bool lazy)
52 #if defined (RTLD_NOW)
53 const int flags = lazy ? RTLD_LAZY : RTLD_NOW;
54 #elif defined (DL_LAZY)
55 const int flags = DL_LAZY;
56 #else
57 const int flags = 0;
58 #endif
60 module_handle_t handle = dlopen (path, flags);
61 if( handle == NULL )
63 msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
64 return -1;
66 *p_handle = handle;
67 return 0;
70 /**
71 * CloseModule: unload a dynamic library
73 * This function unloads a previously opened dynamically linked library
74 * using a system dependent method. No return value is taken in consideration,
75 * since some libraries sometimes refuse to close properly.
76 * \param handle handle of the library
77 * \return nothing
79 void module_Unload( module_handle_t handle )
81 #if !defined(__SANITIZE_ADDRESS__)
82 #ifdef HAVE_VALGRIND_VALGRIND_H
83 if( RUNNING_ON_VALGRIND > 0 )
84 return; /* do not dlclose() so that we get proper stack traces */
85 #endif
86 dlclose( handle );
87 #else
88 (void) handle;
89 #endif
92 /**
93 * Looks up a symbol from a dynamically loaded library
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.
99 * @param handle handle to the module
100 * @param psz_function function name
101 * @return NULL on error, or the address of the symbol
103 void *module_Lookup( module_handle_t handle, const char *psz_function )
105 return dlsym( handle, psz_function );