1 /*****************************************************************************
2 * modules_core.h : Module management functions used by the core application.
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
24 * Inline functions for handling dynamic modules
25 *****************************************************************************/
27 /*****************************************************************************
28 * module_load: load a dynamic library
29 *****************************************************************************
30 * This function loads a dynamically linked library using a system dependant
31 * method, and returns a non-zero value on error, zero otherwise.
32 *****************************************************************************/
34 module_load( char * psz_filename, module_handle_t * handle )
37 *handle = load_add_on( psz_filename );
38 return( *handle < 0 );
40 /* Do not open modules with RTLD_GLOBAL, or we are going to get namespace
41 * collisions when two modules have common public symbols */
42 *handle = dlopen( psz_filename, RTLD_NOW );
43 return( *handle == NULL );
47 /*****************************************************************************
48 * module_unload: unload a dynamic library
49 *****************************************************************************
50 * This function unloads a previously opened dynamically linked library
51 * using a system dependant method. No return value is taken in consideration,
52 * since some libraries sometimes refuse to close properly.
53 *****************************************************************************/
54 static __inline__ void
55 module_unload( module_handle_t handle )
58 unload_add_on( handle );
65 /*****************************************************************************
66 * module_getsymbol: get a symbol from a dynamic library
67 *****************************************************************************
68 * This function queries a loaded library for a symbol specified in a
69 * string, and returns a pointer to it.
70 * FIXME: under Unix we should maybe check for dlerror() instead of the
71 * return value of dlsym, since we could have loaded a symbol really set
72 * to NULL (quite unlikely, though).
73 *****************************************************************************/
74 static __inline__ void *
75 module_getsymbol( module_handle_t handle, char * psz_function )
79 get_image_symbol( handle, psz_function, B_SYMBOL_TYPE_TEXT, &p_symbol );
82 return( dlsym( handle, psz_function ) );
86 /*****************************************************************************
87 * module_error: wrapper for dlerror()
88 *****************************************************************************
89 * This function returns the error message of the last module operation. It
90 * returns the string "failed" on systems which do not have the dlerror()
92 *****************************************************************************/
93 static __inline__ const char *