SharedLibraryPlatform.cpp
Go to the documentation of this file.00001 /*<!--------------------------------------------------------------------> 00002 @file SharedLibraryPlatform.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Summer 2008 00005 00006 @brief 00007 Platform-independent interface for low-level operations on shared, 00008 libraries, including platform-dependent implementations for POSIX-compliant 00009 systems and Windows systems. 00010 <!-------------------------------------------------------------------->**/ 00011 00012 #include "SharedLibraryPlatform.h" 00013 #include <dlfcn.h> 00014 00015 SharedLibraryHandle *SharedLibraryPlatformPosix::load(const std::string &name, 00016 int openFlags) 00017 { 00018 if (openFlags == 0) 00019 openFlags = RTLD_LAZY; 00020 00021 return dlopen(name.c_str(), openFlags); 00022 } 00023 00024 bool SharedLibraryPlatformPosix::unload(SharedLibraryHandle *handle) { 00025 ASSERT(handle != NULL); 00026 int ret = dlclose(handle); 00027 00028 if (0 == ret) // success 00029 return true; 00030 00031 return false; 00032 } 00033 00034 void *SharedLibraryPlatformPosix::getSymbol(SharedLibraryHandle *handle, 00035 const std::string &symbol) 00036 { 00037 ASSERT(handle != NULL); 00038 00039 return dlsym(handle, symbol.c_str()); 00040 } 00041 00042 std::string SharedLibraryPlatformPosix::getLastError() { 00043 char *error = dlerror(); 00044 00045 if (error) 00046 return std::string(error); 00047 00048 return std::string(""); 00049 } 00050
Generated on 28 Feb 2009 for Milton by
1.5.6