summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-05-17 22:45:50 +0200
committerAndreas Baumann <abaumann@yahoo.com>2010-05-17 22:45:50 +0200
commit864cd6ee183952d233da889147f0b419ecd8989d (patch)
treee1f6aec1aa8a39c0b7aa64d1fca1567cb1516dea /src
parentc20ee22f7e0f45d0d025e937877f11132fad6327 (diff)
downloadwolfbones-864cd6ee183952d233da889147f0b419ecd8989d.tar.gz
wolfbones-864cd6ee183952d233da889147f0b419ecd8989d.tar.bz2
added more documentation and dlopen/dlclose, must backport shared library building from SMERP first
Diffstat (limited to 'src')
-rw-r--r--src/library/loader.c52
1 files changed, 47 insertions, 5 deletions
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 <dlfcn.h> /* 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;
}