Skip to content
Snippets Groups Projects
Commit 9f77aafa authored by deuce's avatar deuce
Browse files

Add a cross-platform dlopen() implementation which searches on *nix for

the library since many Linux distros today do not symlink to the *.so file
(I mean you Ubuntu!)
parent 6bec7a6e
No related branches found
No related tags found
No related merge requests found
#include "dirwrap.h"
#include "xp_dl.h"
#if defined(__unix__)
xp_dlopen(const char *name, int mode, int major, int minor)
{
char fname[MAX_PATH+1];
dll_handle ret=NULL;
int i;
/* Try for exact version match */
sprintf(fname, "%s.%d.%d", name, major, minor);
if((dll_handle=dlopen(fname, mode))!=NULL)
return(ret);
/* Try for major version match */
sprintf(fname, "%s.%d", name, major);
if((dll_handle=dlopen(fname, mode))!=NULL)
return(ret);
/* Try for preferred match (symlink) */
if((dll_handle=dlopen(name, mode))!=NULL)
return(ret);
/* Try all previous major versions */
for(i=major-1; i>=0; i--) {
sprintf(fname, "%s.%d", name, i);
if((dll_handle=dlopen(fname, mode))!=NULL)
return(ret);
}
return(NULL);
}
#endif
#endif
#ifndef _XP_DL_H_
#define _XP_DL_H_
#include "wrapdll.h"
#if defined(__unix__)
#include <dlfcn.h>
typedef void * dll_handle;
#define xp_dlsym(handle, name) dlsym(handle, name)
#define xp_dlclose(handle) dlclose(handle)
#elif defined(_WIN32)
#include <Winbase.h>
typedef HMODULE WINAPI dll_handle;
#define xp_dlopen(name, mode, major, minor) LoadLibrary(name)
#define xp_dlsym(handle, name) ((void *)GetProcAddress(handle, name))
#define xp_dlclose(handle) (FreeLibrary(handle)?0:-1)
/* Unused values for *nix compatability */
enum {
RTLD_LAZY
,RTLD_NOW
,RTLD_GLOBAL
,RTLD_LOCAL
,RTLD_TRACE
};
#endif
DLLEXPORT void* DLLCALL xp_dlopen(const char *name, int mode, int major, int minor);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment