diff options
author | Sven Gothel <[email protected]> | 2019-12-12 19:21:00 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-12 19:21:00 +0100 |
commit | 4df06c6894b39af5bf4681c0acf0c1c080084c80 (patch) | |
tree | 2505eb6e3b5798db34033c4cac2d4613bf6bda44 /common/dynload.cpp | |
parent | 8915501ed02eac2b3bce9a7fc06cb1ab562901c3 (diff) | |
parent | c0cf323e1d56ce605e90927324d2fdafcfbb564a (diff) |
merge v1.20.0
Diffstat (limited to 'common/dynload.cpp')
-rw-r--r-- | common/dynload.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/common/dynload.cpp b/common/dynload.cpp new file mode 100644 index 00000000..f1c2a7eb --- /dev/null +++ b/common/dynload.cpp @@ -0,0 +1,44 @@ + +#include "config.h" + +#include "dynload.h" + +#include "strutils.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +void *LoadLib(const char *name) +{ + std::wstring wname{utf8_to_wstr(name)}; + return LoadLibraryW(wname.c_str()); +} +void CloseLib(void *handle) +{ FreeLibrary(static_cast<HMODULE>(handle)); } +void *GetSymbol(void *handle, const char *name) +{ return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name)); } + +#elif defined(HAVE_DLFCN_H) + +#include <dlfcn.h> + +void *LoadLib(const char *name) +{ + dlerror(); + void *handle{dlopen(name, RTLD_NOW)}; + const char *err{dlerror()}; + if(err) handle = nullptr; + return handle; +} +void CloseLib(void *handle) +{ dlclose(handle); } +void *GetSymbol(void *handle, const char *name) +{ + dlerror(); + void *sym{dlsym(handle, name)}; + const char *err{dlerror()}; + if(err) sym = nullptr; + return sym; +} +#endif |