diff options
Diffstat (limited to 'src/library/loader.c')
-rw-r--r-- | src/library/loader.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/library/loader.c b/src/library/loader.c index cf5f0e3..b8a3d1b 100644 --- a/src/library/loader.c +++ b/src/library/loader.c @@ -24,14 +24,24 @@ #include "port/gettext.h" /* for i18n */ #include "port/string.h" /* for strncpy */ -#ifdef HAVE_DLFCN +#if defined HAVE_DLFCN #include <dlfcn.h> /* for dlopen. dlclose functions */ #endif +#if defined _WIN32 +#define WIN32_MEAN_AND_LEAN +#include <windows.h> +#endif + #define INTERNAL_ERRBUF_SIZE 256 struct wolf_library_t { - void *handle; /**< the OS handle for the library */ +#if defined HAVE_DLFCN + void *handle; /**< the OS handle for a library */ +#endif +#if defined _WIN32 + HMODULE handle; /**< the windows handle for a library */ +#endif char errbuf[INTERNAL_ERRBUF_SIZE]; /**< internal buffer to hold the error message * we get with dlerror */ }; @@ -59,25 +69,50 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { return l; } #else +#if defined _WIN32 + l->handle = LoadLibrary( name ); + if( l->handle == NULL ) { + strncpy( l->errbuf, "<TODO: GetLastError>", INTERNAL_ERRBUF_SIZE ); + *error = WOLF_ERR_INTERNAL; + return l; + } +#else #error Not using DLFCN as shared loader. Port first! #endif +#endif *error = WOLF_OK; return l; } wolf_error_t wolf_library_unload( wolf_library_p l ) { +#if !defined _WIN32 int res = 0; +#else + BOOL res = FALSE; +#endif if( l == NULL || l->handle == NULL ) { return WOLF_ERR_INVALID_STATE; } +#if defined HAVE_DLFCN res = dlclose( l->handle ); if( res != 0 ) { strncpy( l->errbuf, dlerror( ), INTERNAL_ERRBUF_SIZE ); return WOLF_ERR_INTERNAL; } +#else +#if defined _WIN32 + res = FreeLibrary( l->handle ); + if( !res ) { + strncpy( l->errbuf, "<TODO: GetLastError>", INTERNAL_ERRBUF_SIZE ); + return WOLF_ERR_INTERNAL; + } +#else +#error Not using DLFCN as shared loader. Port first! +#endif +#endif free( l ); l = NULL; @@ -98,7 +133,15 @@ char *wolf_library_errmsg( const wolf_error_t error, const wolf_library_p librar void *wolf_library_get( const wolf_library_p l, const char *name, wolf_error_t *error ) { void *ret; +#if defined HAVE_DLFCN ret = dlsym( l->handle, name ); +#else +#if defined _WIN32 + +#else +#error Not using DLFCN as shared loader. Port first! +#endif +#endif *error = WOLF_OK; return ret; |