aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Puccinelli2010-08-03 06:25:03 +0000
committerTony Puccinelli2010-08-03 06:25:03 +0000
commit934c0b922c3927a203f2027f73a472fff5c48d4b (patch)
treeef48b2b212c7a8af37dbddee2a9adabe33203d29
parentd889a706f20c7d37ab56feb182fe14d04fb2cd4f (diff)
downloadscummvm-rg350-934c0b922c3927a203f2027f73a472fff5c48d4b.tar.gz
scummvm-rg350-934c0b922c3927a203f2027f73a472fff5c48d4b.tar.bz2
scummvm-rg350-934c0b922c3927a203f2027f73a472fff5c48d4b.zip
got rid of dlopen, dlclose, etc. wrappers
svn-id: r51677
-rw-r--r--backends/plugins/elf-loader.cpp41
-rw-r--r--backends/plugins/elf-loader.h1
-rw-r--r--backends/plugins/elf-provider.cpp38
3 files changed, 30 insertions, 50 deletions
diff --git a/backends/plugins/elf-loader.cpp b/backends/plugins/elf-loader.cpp
index 33f97f5586..1b70ed5565 100644
--- a/backends/plugins/elf-loader.cpp
+++ b/backends/plugins/elf-loader.cpp
@@ -448,46 +448,5 @@ void *DLObject::symbol(const char *name) {
return NULL;
}
-
-static char dlerr[MAXDLERRLEN];
-
-void *dlopen(const char *filename, int flags) {
- DLObject *obj = new DLObject(dlerr);
- if (obj->open(filename))
- return (void *)obj;
- delete obj;
- return NULL;
-}
-
-int dlclose(void *handle) {
- DLObject *obj = (DLObject *)handle;
- if (obj == NULL) {
- strcpy(dlerr, "Handle is NULL.");
- return -1;
- }
- if (obj->close()) {
- delete obj;
- return 0;
- }
- return -1;
-}
-
-void *dlsym(void *handle, const char *symbol) {
- if (handle == NULL) {
- strcpy(dlerr, "Handle is NULL.");
- return NULL;
- }
- return ((DLObject *)handle)->symbol(symbol);
-}
-
-const char *dlerror() {
- return dlerr;
-}
-
-void dlforgetsyms(void *handle) {
- if (handle != NULL)
- ((DLObject *)handle)->discard_symtab();
-}
-
#endif /* DYNAMIC_MODULES */
diff --git a/backends/plugins/elf-loader.h b/backends/plugins/elf-loader.h
index 3f33b681bf..d6273b7e71 100644
--- a/backends/plugins/elf-loader.h
+++ b/backends/plugins/elf-loader.h
@@ -93,7 +93,6 @@ public:
extern "C" {
void *dlopen(const char *filename, int flags);
int dlclose(void *handle);
- void *dlsym(void *handle, const char *symbol);
const char *dlerror();
void dlforgetsyms(void *handle);
}
diff --git a/backends/plugins/elf-provider.cpp b/backends/plugins/elf-provider.cpp
index b623f0d881..4d4c66084d 100644
--- a/backends/plugins/elf-provider.cpp
+++ b/backends/plugins/elf-provider.cpp
@@ -31,6 +31,7 @@
#include "backends/plugins/elf-loader.h"
+static char dlerr[MAXDLERRLEN];
class ELFPlugin : public DynamicPlugin {
protected:
@@ -38,9 +39,15 @@ protected:
Common::String _filename;
virtual VoidFunc findSymbol(const char *symbol) {
- void *func = dlsym(_dlHandle, symbol);
+ void *func;
+ if (_dlHandle == NULL) {
+ strcpy(dlerr, "Handle is NULL.");
+ func = NULL;
+ } else {
+ func = ((DLObject *)_dlHandle)->symbol(symbol);
+ }
if (!func)
- warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
+ warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerr);
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
@@ -62,17 +69,25 @@ public:
bool loadPlugin() {
assert(!_dlHandle);
- _dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
+ DLObject *obj = new DLObject(dlerr);
+ if (obj->open(_filename.c_str())) {
+ _dlHandle = (void *)obj;
+ } else {
+ delete obj;
+ _dlHandle = NULL;
+ }
if (!_dlHandle) {
- warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
+ warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerr);
return false;
}
bool ret = DynamicPlugin::loadPlugin();
- if (ret)
- dlforgetsyms(_dlHandle);
+ if (ret) {
+ if (_dlHandle != NULL)
+ ((DLObject *)_dlHandle)->discard_symtab();
+ }
return ret;
}
@@ -80,8 +95,15 @@ public:
void unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
- if (dlclose(_dlHandle) != 0)
- warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
+ DLObject *obj = (DLObject *)_dlHandle;
+ if (obj == NULL) {
+ strcpy(dlerr, "Handle is NULL.");
+ warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerr);
+ } else if (obj->close()) {
+ delete obj;
+ } else {
+ warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerr);
+ }
_dlHandle = 0;
}
}