mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-01-08 09:49:57 +01:00
use dlopen to load dynamic libraries
This commit is contained in:
parent
25badde4c9
commit
2c3a019717
|
|
@ -1,18 +1,11 @@
|
|||
/* Handle to devil Library */
|
||||
#ifdef _WIN32
|
||||
#include "extil.h"
|
||||
static HMODULE devILhandle;
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#include "extil.h"
|
||||
static void* devILhandle;
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
#include <mach-o/dyld.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
const struct mach_header* devILhandle = NULL;
|
||||
#include "extil.h"
|
||||
#include "extil.h"
|
||||
static HMODULE devILhandle;
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include "extil.h"
|
||||
static void* devILhandle;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -22,22 +15,9 @@ const struct mach_header* devILhandle = NULL;
|
|||
static void *NativeGetFunctionPointer(const char *function) {
|
||||
#ifdef _WIN32
|
||||
return GetProcAddress(devILhandle, function);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
return dlsym(devILhandle, function);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char));
|
||||
if (mac_symbol_name == NULL)
|
||||
return NULL;
|
||||
mac_symbol_name[0] = '_';
|
||||
strcpy(&(mac_symbol_name[1]), function);
|
||||
NSSymbol symbol = NSLookupSymbolInImage(devILhandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
free(mac_symbol_name);
|
||||
if (symbol == NULL)
|
||||
return NULL;
|
||||
return NSAddressOfSymbol(symbol);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,12 +57,11 @@ bool extil_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
printfDebug("Testing '%s'\n", path_str);
|
||||
#ifdef _WIN32
|
||||
devILhandle = LoadLibrary(path_str);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
devILhandle = dlopen(path_str, RTLD_LAZY);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
devILhandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
if(devILhandle == NULL) {
|
||||
printfDebug("dlopen failure: %s", dlerror());
|
||||
}
|
||||
#endif
|
||||
if (devILhandle != NULL) {
|
||||
printfDebug("Found devil at '%s'\n", path_str);
|
||||
|
|
@ -103,14 +82,10 @@ bool extil_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
void extil_Close(void) {
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(devILhandle);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
if (devILhandle != NULL) {
|
||||
dlclose(devILhandle);
|
||||
}
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
// Cannot remove the image
|
||||
#endif
|
||||
devILhandle = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,11 @@
|
|||
/* Handle to ilu Library */
|
||||
#ifdef _WIN32
|
||||
#include "extilu.h"
|
||||
static HMODULE devILUhandle;
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#include "extilu.h"
|
||||
static void* devILUhandle;
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
#include <mach-o/dyld.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
static const struct mach_header* devILUhandle;
|
||||
#include "extilu.h"
|
||||
#include "extilu.h"
|
||||
static HMODULE devILUhandle;
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include "extilu.h"
|
||||
static void* devILUhandle;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -22,22 +15,9 @@ static const struct mach_header* devILUhandle;
|
|||
static void *NativeGetFunctionPointer(const char *function) {
|
||||
#ifdef _WIN32
|
||||
return GetProcAddress(devILUhandle, function);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
return dlsym(devILUhandle, function);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char));
|
||||
if (mac_symbol_name == NULL)
|
||||
return NULL;
|
||||
mac_symbol_name[0] = '_';
|
||||
strcpy(&(mac_symbol_name[1]), function);
|
||||
NSSymbol symbol = NSLookupSymbolInImage(devILUhandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
free(mac_symbol_name);
|
||||
if (symbol == NULL)
|
||||
return NULL;
|
||||
return NSAddressOfSymbol(symbol);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,12 +57,11 @@ bool extilu_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
printfDebug("Testing '%s'\n", path_str);
|
||||
#ifdef _WIN32
|
||||
devILUhandle = LoadLibrary(path_str);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
devILUhandle = dlopen(path_str, RTLD_LAZY);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
devILUhandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
if(devILUhandle == NULL) {
|
||||
printfDebug("dlopen failure: %s", dlerror());
|
||||
}
|
||||
#endif
|
||||
if (devILUhandle != NULL) {
|
||||
printfDebug("Found ilu at '%s'\n", path_str);
|
||||
|
|
@ -103,14 +82,10 @@ bool extilu_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
void extilu_Close(void) {
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(devILUhandle);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
if (devILUhandle != NULL) {
|
||||
dlclose(devILUhandle);
|
||||
}
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
// Cannot remove the image
|
||||
#endif
|
||||
devILUhandle = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,11 @@
|
|||
/* Handle to ilut Library */
|
||||
#ifdef _WIN32
|
||||
#include "extilut.h"
|
||||
static HMODULE devILUThandle;
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#include "extilut.h"
|
||||
static void* devILUThandle;
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
#include <mach-o/dyld.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
static const struct mach_header* devILUThandle;
|
||||
#include "extilut.h"
|
||||
#include "extilut.h"
|
||||
static HMODULE devILUThandle;
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#include "extilut.h"
|
||||
static void* devILUThandle;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -22,22 +15,9 @@ static const struct mach_header* devILUThandle;
|
|||
static void *NativeGetFunctionPointer(const char *function) {
|
||||
#ifdef _WIN32
|
||||
return GetProcAddress(devILUThandle, function);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
return dlsym(devILUThandle, function);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char));
|
||||
if (mac_symbol_name == NULL)
|
||||
return NULL;
|
||||
mac_symbol_name[0] = '_';
|
||||
strcpy(&(mac_symbol_name[1]), function);
|
||||
NSSymbol symbol = NSLookupSymbolInImage(devILUThandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
free(mac_symbol_name);
|
||||
if (symbol == NULL)
|
||||
return NULL;
|
||||
return NSAddressOfSymbol(symbol);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,12 +57,11 @@ bool extilut_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
printfDebug("Testing '%s'\n", path_str);
|
||||
#ifdef _WIN32
|
||||
devILUThandle = LoadLibrary(path_str);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
devILUThandle = dlopen(path_str, RTLD_LAZY);
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
devILUThandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
if(devILUThandle == NULL) {
|
||||
printfDebug("dlopen failure: %s", dlerror());
|
||||
}
|
||||
#endif
|
||||
if (devILUThandle != NULL) {
|
||||
printfDebug("Found ilut at '%s'\n", path_str);
|
||||
|
|
@ -103,14 +82,10 @@ bool extilut_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|||
void extilut_Close(void) {
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(devILUThandle);
|
||||
#endif
|
||||
#ifdef _X11
|
||||
#else
|
||||
if (devILUThandle != NULL) {
|
||||
dlclose(devILUThandle);
|
||||
}
|
||||
#endif
|
||||
#ifdef _MACOSX
|
||||
// Cannot remove the image
|
||||
#endif
|
||||
devILUThandle = NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue