summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dynamic.h6
-rw-r--r--src/dynamic.cpp36
2 files changed, 21 insertions, 21 deletions
diff --git a/include/dynamic.h b/include/dynamic.h
index 905eb479e..c14452f8c 100644
--- a/include/dynamic.h
+++ b/include/dynamic.h
@@ -59,6 +59,12 @@ class CoreExport DLLManager : public classbase
*/
Module* CallInit();
+ /** Retrieves the value of the specified symbol.
+ * @param name The name of the symbol to retrieve.
+ * @return Either the value of the specified symbol or or NULL if it does not exist.
+ */
+ void* GetSymbol(const char* name);
+
/** Get detailed version information from the module file */
std::string GetVersion();
};
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<const char*>(GetSymbol("inspircd_src_version"));
+ return srcver ? srcver : "";
}
void DLLManager::RetrieveLastError()