blob: 98d2c521846af6ac685ede2b22d8445f8bcfc094 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include "config.h"
#include "dynload.h"
#include "strutils.h"
#ifdef _WIN32
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
|