]> git.tdb.fi Git - ext/openal.git/blob - common/dynload.cpp
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / common / dynload.cpp
1
2 #include "config.h"
3
4 #include "dynload.h"
5
6 #include "strutils.h"
7
8 #ifdef _WIN32
9 #define WIN32_LEAN_AND_MEAN
10 #include <windows.h>
11
12 void *LoadLib(const char *name)
13 {
14     std::wstring wname{utf8_to_wstr(name)};
15     return LoadLibraryW(wname.c_str());
16 }
17 void CloseLib(void *handle)
18 { FreeLibrary(static_cast<HMODULE>(handle)); }
19 void *GetSymbol(void *handle, const char *name)
20 { return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name)); }
21
22 #elif defined(HAVE_DLFCN_H)
23
24 #include <dlfcn.h>
25
26 void *LoadLib(const char *name)
27 {
28     dlerror();
29     void *handle{dlopen(name, RTLD_NOW)};
30     const char *err{dlerror()};
31     if(err) handle = nullptr;
32     return handle;
33 }
34 void CloseLib(void *handle)
35 { dlclose(handle); }
36 void *GetSymbol(void *handle, const char *name)
37 {
38     dlerror();
39     void *sym{dlsym(handle, name)};
40     const char *err{dlerror()};
41     if(err) sym = nullptr;
42     return sym;
43 }
44 #endif