From 864cd6ee183952d233da889147f0b419ecd8989d Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 17 May 2010 22:45:50 +0200 Subject: added more documentation and dlopen/dlclose, must backport shared library building from SMERP first --- src/library/loader.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/library/loader.c b/src/library/loader.c index e0bb055..1f8ce20 100644 --- a/src/library/loader.c +++ b/src/library/loader.c @@ -16,20 +16,62 @@ */ #include "library/loader.h" +#include "port/sys_internal.h" #include "port/unused.h" #include "port/stdlib.h" /* for malloc, free */ +#ifdef HAVE_DLFCN +#include /* for dlopen. dlclose functions */ +#endif + struct wolf_library_t { - char dummy; /**< dummy */ + void *handle; /**< the OS handle for the library */ }; wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { - WOLF_UNUSED( name ); + wolf_library_p l; + int flags = 0; + + l = (struct wolf_library_t *)malloc( sizeof ( struct wolf_library_t ) ); + if( l == NULL ) { + *error = WOLF_ERR_OUT_OF_MEMORY; + return NULL; + } + +#if defined HAVE_DLFCN + /* TODO: Apache has a flags variable and a direct parameter version, find out why.. + * also make up our bind how many flags we should "leak" to the application layer + */ + flags = RTLD_NOW | RTLD_LOCAL; + + l->handle = dlopen( name, flags ); + if( l->handle == NULL ) { + *error = WOLF_ERR_INTERNAL; + return NULL; + } +#else +#error Not using DLFCN as shared loader. Port first! +#endif + *error = WOLF_OK; - return NULL; + return l; } -void wolf_library_unload( wolf_library_p library ) { - WOLF_UNUSED( library ); +wolf_error_t wolf_library_unload( wolf_library_p l ) { + int res = 0; + + if( l == NULL || l->handle == NULL ) { + return WOLF_ERR_INVALID_STATE; + } + + res = dlclose( l->handle ); + if( res != 0 ) { + return WOLF_ERR_INVALID_STATE; + } + + free( l ); + l = NULL; + + return WOLF_OK; } -- cgit v1.2.3-54-g00ecf