diff options
-rw-r--r-- | include/GNUmakefile | 4 | ||||
-rw-r--r-- | include/Makefile.W32 | 10 | ||||
-rw-r--r-- | include/wolf/errors.h | 2 | ||||
-rw-r--r-- | include/wolf/library/loader.h | 2 | ||||
-rw-r--r-- | src/Makefile.W32 | 7 | ||||
-rw-r--r-- | src/library/loader.c | 47 | ||||
-rw-r--r-- | tests/Makefile.W32 | 2 | ||||
-rw-r--r-- | tests/library/Makefile.W32 | 28 |
8 files changed, 94 insertions, 8 deletions
diff --git a/include/GNUmakefile b/include/GNUmakefile index e7c40c2..2d1dcbd 100644 --- a/include/GNUmakefile +++ b/include/GNUmakefile @@ -13,6 +13,8 @@ local_clean: -@rm -f wolf/log/*~ -@rm -f wolf/daemon/*.bak -@rm -f wolf/daemon/*~ + -@rm -f wolf/library/*.bak + -@rm -f wolf/library/*~ local_install: $(INSTALL) -d -m 755 $(includedir)/wolf @@ -23,3 +25,5 @@ local_install: $(INSTALL) -m 644 wolf/log/*.h $(includedir)/wolf/log $(INSTALL) -d -m 755 $(includedir)/wolf/daemon $(INSTALL) -m 644 wolf/daemon/*.h $(includedir)/wolf/daemon + $(INSTALL) -d -m 755 $(includedir)/wolf/library + $(INSTALL) -m 644 wolf/daemon/*.h $(includedir)/wolf/library diff --git a/include/Makefile.W32 b/include/Makefile.W32 index ff4b18e..61bff47 100644 --- a/include/Makefile.W32 +++ b/include/Makefile.W32 @@ -9,8 +9,12 @@ local_clean: @-erase wolf\*~ 2>NUL @-erase wolf\port\*.bak 2>NUL @-erase wolf\port\*~ 2>NUL - @-erase wolf\daemon\*.bak 2>NUL - @-erase wolf\daemon\*~ 2>NUL + @-erase wolf\log\*.bak 2>NUL + @-erase wolf\log\*~ 2>NUL + @-erase wolf\service\*.bak 2>NUL + @-erase wolf\service\*~ 2>NUL + @-erase wolf\library\*.bak 2>NUL + @-erase wolf\library\*~ 2>NUL local_distclean: @@ -23,3 +27,5 @@ local_test: # $(INSTALL) -m 644 wolf/daemon/*.h $(includedir)/wolf/daemon # $(INSTALL) -d -m 755 $(includedir)/wolf/port # $(INSTALL) -m 644 wolf/port/*.h $(includedir)/wolf/port +# $(INSTALL) -d -m 755 $(includedir)/wolf/library +# $(INSTALL) -m 644 wolf/daemon/*.h $(includedir)/wolf/library diff --git a/include/wolf/errors.h b/include/wolf/errors.h index 0b14356..96b6e2f 100644 --- a/include/wolf/errors.h +++ b/include/wolf/errors.h @@ -33,7 +33,7 @@ extern "C" { #endif -#include <sys/types.h> /* for size_t */ +#include <stddef.h> /* for size_t */ /** * @brief Possible error codes of the various libwolf libraries. diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h index 2218677..76cf5ee 100644 --- a/include/wolf/library/loader.h +++ b/include/wolf/library/loader.h @@ -36,7 +36,7 @@ extern "C" { #include "port/sys.h" #include "errors.h" -#include <sys/types.h> /* for size_t */ +#include <stddef.h> /* for size_t */ /* @brief handle representing a shared library */ diff --git a/src/Makefile.W32 b/src/Makefile.W32 index d0f7a99..d606df9 100644 --- a/src/Makefile.W32 +++ b/src/Makefile.W32 @@ -29,11 +29,16 @@ LOG_OBJS = \ SERVICE_OBJS = \ service\service.obj +LIBRARY_OBJS = \ + library\loader.obj + OBJS = \ + errors.obj \ $(THREADING_OBJS) \ $(PORT_OBJS) \ $(LOG_OBJS) \ - $(SERVICE_OBJS) + $(SERVICE_OBJS) \ + $(LIBRARY_OBJS) local_all: $(LIBRARIES) 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; diff --git a/tests/Makefile.W32 b/tests/Makefile.W32 index 2b592c9..13f17c4 100644 --- a/tests/Makefile.W32 +++ b/tests/Makefile.W32 @@ -1,6 +1,6 @@ TOPDIR = .. -SUBDIRS = threads port log network service +SUBDIRS = threads port log network service library !INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk diff --git a/tests/library/Makefile.W32 b/tests/library/Makefile.W32 new file mode 100644 index 0000000..4ebcab9 --- /dev/null +++ b/tests/library/Makefile.W32 @@ -0,0 +1,28 @@ +TOPDIR = ..\.. + +INCLUDE_DIRS = \ + /I$(TOPDIR)\include\wolf /I. /I$(TOPDIR)\src \ + /D_WIN32_WINNT=0x400 /I"$(PLATFORM_SDK_DIR)\Include" + +INCLUDE_LDFLAGS = \ + /LIBPATH:"$(PLATFORM_SDK_DIR)\lib" + +INCLUDE_LIBS = \ + $(TOPDIR)\src\wolf.lib + +TEST_BINS = \ + test_loader.exe + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +test_loader.exe: test_loader.obj $(TOPDIR)\src\wolf.lib + +local_all: + +local_clean: + +local_distclean: + +local_test: $(LIBRARIES) + @echo Testing loading of a library and executing a function therein.. + @test_loader 2>NUL |