diff options
-rw-r--r-- | Alc/ALc.c | 62 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 16 |
2 files changed, 78 insertions, 0 deletions
@@ -44,6 +44,9 @@ DEFINE_GUID(IID_IAudioRenderClient, 0xf294acfc, 0x3146, 0x4483, 0xa7,0xbf, 0xad, #include <stdio.h> #include <memory.h> #include <ctype.h> +#ifdef HAVE_DLFCN_H +#include <dlfcn.h> +#endif #include "alMain.h" #include "alSource.h" @@ -1065,6 +1068,65 @@ void LeaveCriticalSection(CRITICAL_SECTION *cs) } #endif +#if defined(_WIN32) +void *LoadLib(const char *name) +{ + HANDLE handle; + + handle = LoadLibraryA(name); + if(handle == NULL) + AL_PRINT("Failed to open %s\n", name); + return handle; +} + +void CloseLib(void *handle) +{ FreeLibrary((HANDLE)handle); } + +void *GetSymbol(void *handle, const char *name) +{ + void *ret; + + ret = (void*)GetProcAddress((HANDLE)handle, name); + if(ret == NULL) + AL_PRINT("Failed to load %s\n", name); + return ret; +} + +#elif defined(HAVE_DLFCN_H) + +void *LoadLib(const char *name) +{ + const char *err; + void *handle; + + dlerror(); + handle = dlopen(name, RTLD_NOW); + if((err=dlerror()) != NULL) + { + AL_PRINT("Failed to open %s: %s\n", name, err); + handle = NULL; + } + return handle; +} + +void CloseLib(void *handle) +{ dlclose(handle); } + +void *GetSymbol(void *handle, const char *name) +{ + const char *err; + void *sym; + + dlerror(); + sym = dlsym(handle, name); + if((err=dlerror()) != NULL) + { + AL_PRINT("Failed to load %s: %s\n", name, err); + sym = NULL; + } + return sym; +} +#endif static void LockLists(void) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 8df5a4b9..2a504ffa 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -192,6 +192,8 @@ typedef DWORD tls_type; #define tls_get(x) TlsGetValue((x)) #define tls_set(x, a) TlsSetValue((x), (a)) +#define HAVE_DYNLOAD 1 + #else #include <unistd.h> @@ -261,8 +263,14 @@ static __inline void Sleep(ALuint t) while(nanosleep(&tv, &rem) == -1 && errno == EINTR) tv = rem; } + #define min(x,y) (((x)<(y))?(x):(y)) #define max(x,y) (((x)>(y))?(x):(y)) + +#if defined(HAVE_DLFCN_H) +#define HAVE_DYNLOAD 1 +#endif + #endif #include "alListener.h" @@ -577,6 +585,14 @@ void al_print(const char *fname, unsigned int line, const char *fmt, ...) PRINTF_STYLE(3,4); #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__) + +#if defined(_WIN32) || defined(HAVE_DLFCN_H) +#define HAVE_DYNLOAD 1 +void *LoadLib(const char *name); +void CloseLib(void *handle); +void *GetSymbol(void *handle, const char *name); +#endif + extern ALdouble ConeScale; extern ALdouble ZScale; |