38#include "blocxx/BLOCXX_config.h"
39#if defined(BLOCXX_USE_DL)
46#ifdef BLOCXX_HAVE_FCNTL_H
53#if defined(BLOCXX_USE_FAKE_LIBS)
59#define BLOCXX_FAKELIB_HEADING "FAKE"
60#define BLOCXX_FAKELIB_HEADING_LENGTH 4
70bool dlSharedLibrary::s_call_dlclose =
true;
74dlSharedLibrary::dlSharedLibrary(
void * libhandle,
const String& libName)
75 :
SharedLibrary(), m_libhandle( libhandle ), m_libName(libName)
77#if defined(BLOCXX_USE_FAKE_LIBS)
79 m_fakeLibrary = dlSharedLibrary::isFakeLibrary(libName);
83 initializeSymbolMap();
88dlSharedLibrary::~dlSharedLibrary()
90#if !defined(BLOCXX_VALGRIND_SUPPORT)
93 dlclose( m_libhandle );
97bool dlSharedLibrary::doGetFunctionPointer(
const String& functionName,
100 MutexLock l(dlSharedLibrary_guard);
101#if defined(BLOCXX_USE_FAKE_LIBS)
102 String realFunctionName = functionName;
107 Map<String,String>::const_iterator symIter = m_symbolMap.find(functionName);
108 if ( symIter == m_symbolMap.end() )
112 realFunctionName = symIter->second;
114 *fp = dlsym( m_libhandle, realFunctionName.c_str() );
116 *fp = dlsym( m_libhandle, functionName.c_str() );
126bool dlSharedLibrary::isFakeLibrary(
const String& library_path)
129#if defined(BLOCXX_USE_FAKE_LIBS)
130 if ( FileSystem::canRead(library_path) )
134 int libfd = open(library_path.c_str(), O_RDONLY);
138 char buffer[(BLOCXX_FAKELIB_HEADING_LENGTH) + 1];
139 size_t num_read =
read(libfd, buffer,(BLOCXX_FAKELIB_HEADING_LENGTH));
140 if ( num_read == (BLOCXX_FAKELIB_HEADING_LENGTH) )
143 buffer[BLOCXX_FAKELIB_HEADING_LENGTH] =
'\0';
144 if ( String(BLOCXX_FAKELIB_HEADING) == buffer )
157#if defined(BLOCXX_USE_FAKE_LIBS)
158void dlSharedLibrary::initializeSymbolMap()
160 if ( ! m_fakeLibrary )
167 StringArray lines = FileSystem::getFileLines(m_libName);
169 for ( StringArray::const_iterator iter = lines.begin();
174 if ( iter->startsWith(
'#') )
180 if ( current_line.size() != 2 )
185 String option = String(current_line[0]).trim();
186 String value = String(current_line[1]).trim();
187 m_symbolMap[option] = value;
#define BLOCXX_GLOBAL_MUTEX_INIT()
SharedLibrary is a base class for platform classes that implement the functionality of loading and qu...
This String class is an abstract data type that represents as NULL terminated string of characters.
void read(std::streambuf &istrm, void *dataIn, size_t dataInLen)
BLOCXX_COMMON_API int close(const FileHandle &hdl)
Close file handle.
Array< String > StringArray
LazyGlobal< Mutex, int, GlobalMutexFactory > GlobalMutex