diff options
Diffstat (limited to 'src/dynamic.cpp')
-rw-r--r-- | src/dynamic.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/dynamic.cpp b/src/dynamic.cpp index d111da548..f2acdd51c 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -22,7 +22,7 @@ #include "inspircd.h" -#include "dynamic.h" + #ifndef _WIN32 #include <dlfcn.h> #else @@ -54,36 +54,30 @@ DLLManager::~DLLManager() dlclose(h); } -union init_t { - void* vptr; - Module* (*fptr)(); -}; - Module* DLLManager::CallInit() { - if (!h) - return NULL; - - init_t initfn; - initfn.vptr = dlsym(h, MODULE_INIT_STR); - if (!initfn.vptr) + union { - RetrieveLastError(); + void* vptr; + Module* (*fptr)(); + }; + + vptr = GetSymbol(MODULE_INIT_STR); + if (!vptr) return NULL; - } - return (*initfn.fptr)(); + return (*fptr)(); } -std::string DLLManager::GetVersion() +void* DLLManager::GetSymbol(const char* name) { - if (!h) - return ""; + return h ? dlsym(h, name) : NULL; +} - const char* srcver = (char*)dlsym(h, "inspircd_src_version"); - if (srcver) - return srcver; - return "Unversioned module"; +std::string DLLManager::GetVersion() +{ + const char* srcver = static_cast<const char*>(GetSymbol("inspircd_src_version")); + return srcver ? srcver : ""; } void DLLManager::RetrieveLastError() |