From 8d87fa3837d26f11b1233badbe7ec540d38a686b Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 4 Feb 2019 23:37:54 +0000 Subject: DLLManager: add a function for retrieving a symbol. --- src/dynamic.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/dynamic.cpp b/src/dynamic.cpp index 08564a0cd..f2acdd51c 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -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 ""; +std::string DLLManager::GetVersion() +{ + const char* srcver = static_cast(GetSymbol("inspircd_src_version")); + return srcver ? srcver : ""; } void DLLManager::RetrieveLastError() -- cgit v1.2.3