Add wrappers to handle dyanmically loading libs

This commit is contained in:
Chris Robinson 2011-06-12 04:36:24 -07:00
parent 6bfab6427a
commit ccf62fc525
2 changed files with 78 additions and 0 deletions

View File

@ -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)
{

View File

@ -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;