diff options
author | Karroffel <therzog@mail.de> | 2017-03-08 02:50:13 +0100 |
---|---|---|
committer | Karroffel <therzog@mail.de> | 2017-03-29 23:05:15 +0200 |
commit | 2281942fb3ac5889abc6e95df27a80e71fe32c0e (patch) | |
tree | 770e8ac3c7b7b8b241a04eb7495405e6d0a0068d /drivers | |
parent | 92b6c8095acc8348da7657dde357202840c26382 (diff) |
Added methods for opening dynamic libraries to OS
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/unix/os_unix.cpp | 30 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 4 |
2 files changed, 34 insertions, 0 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index e2a544b676..999e20621b 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -54,6 +54,7 @@ #endif #include "global_config.h" #include <assert.h> +#include <dlfcn.h> #include <errno.h> #include <poll.h> #include <signal.h> @@ -435,6 +436,35 @@ String OS_Unix::get_locale() const { return locale; } +Error OS_Unix::open_dynamic_library(const String p_path, void* &p_library_handle) { + p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW); + if(!p_library_handle) { + ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); + ERR_FAIL_V(ERR_CANT_OPEN); + } + return OK; +} + +Error OS_Unix::close_dynamic_library(void* p_library_handle) { + if(dlclose(p_library_handle)) { + return FAILED; + } + return OK; +} + +Error OS_Unix::get_dynamic_library_symbol_handle(void* p_library_handle, const String p_name, void* &p_symbol_handle) { + char* error; + dlerror(); // Clear existing errors + + p_symbol_handle = dlsym(p_library_handle, p_name.utf8().get_data()); + + if ((error = dlerror()) != NULL) { + ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + dlerror()); + ERR_FAIL_V(ERR_CANT_RESOLVE); + } + return OK; +} + Error OS_Unix::set_cwd(const String &p_cwd) { if (chdir(p_cwd.utf8().get_data()) != 0) diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 3ac4f46109..771421ec35 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -82,6 +82,10 @@ public: //virtual VideoMode get_video_mode() const; //virtual void get_fullscreen_mode_list(List<VideoMode> *p_list) const; + virtual Error open_dynamic_library(const String p_path, void* &p_library_handle); + virtual Error close_dynamic_library(void* p_library_handle); + virtual Error get_dynamic_library_symbol_handle(void* p_library_handle, const String p_name, void* &p_symbol_handle); + virtual Error set_cwd(const String &p_cwd); virtual String get_name(); |