aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-06-12 04:36:24 -0700
committerChris Robinson <[email protected]>2011-06-12 04:36:24 -0700
commitccf62fc525d8649adfa3359a5dfde9c64336ffab (patch)
treef7496ea22d404b6bcc288ff68ca3c0f018abb169 /Alc
parent6bfab6427a40de60a7b4c12bce7cf1a687a33e2d (diff)
Add wrappers to handle dyanmically loading libs
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 9c4dd977..1438694e 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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)
{