7 # include "CLAM_windows.h"
23 std::list<std::string>::const_iterator itLibraries;
25 for (itLibraries=usedLibraries.begin();itLibraries!=usedLibraries.end();itLibraries++)
28 keys=factory.
GetKeys(
"library",(*itLibraries));
29 CLAM::ProcessingFactory::Keys::const_iterator itKeys;
31 for(itKeys=keys.begin();itKeys!=keys.end();itKeys++)
47 std::list<std::string> usedLibraries;
49 CLAM::ProcessingFactory::Values::const_iterator itLibraries;
50 for (itLibraries=librariesValues.begin();itLibraries!=librariesValues.end();itLibraries++)
54 usedLibraries.push_back(*itLibraries);
61 std::string paths = GetPaths();
63 for (
unsigned i=0; i<environmentPaths.size(); i++)
65 if (environmentPaths[i]==path)
73 std::string path = GetPaths();
76 for (
unsigned i=0; i<environmentPaths.size(); i++)
78 debug && std::cout <<
"RunTimeLibraryLoader: Scanning for libraries in " << environmentPaths[i] << std::endl;
84 DIR* dir = opendir(path.c_str());
86 while (
struct dirent * dirEntry = readdir(dir) )
88 std::string pluginFilename(dirEntry->d_name);
89 if(pluginFilename ==
"." || pluginFilename ==
"..")
91 debug && std::cout <<
"RunTimeLibraryLoader: Found file " << pluginFilename << std::endl;
92 std::string pluginFullFilename(path + std::string(
"/") + pluginFilename);
98 std::cout <<
"Error loading: " << pluginFullFilename
114 return LoadLibrary(libraryPath.c_str());
116 return dlopen( libraryPath.c_str(), RTLD_NOW);
127 return dlopen( libraryPath.c_str(), RTLD_LAZY);
135 return (
void*) GetProcAddress((HMODULE)libraryHandler, symbolName.c_str());
137 return dlsym(libraryHandler, symbolName.c_str());
144 #ifdef WIN32 //TODO: does windows have an equivalent method to have the handler?
147 return dlopen (libraryPath.c_str(), RTLD_NOLOAD);
157 std::cout<<
"Cannot release an empty handle!"<<std::endl;
161 return !FreeLibrary((HMODULE)handle);
163 return dlclose(handle);
172 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
175 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
178 std::string message((
char*)lpMsgBuf);
189 char pluginpath[1024];
192 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
193 (
char *)symbolAddress,
195 GetModuleFileNameA(module, pluginpath, 1024);
200 int ok=dladdr(symbolAddress,&info);
202 return info.dli_fname;
209 std::string content=pathVariable;
210 std::vector<std::string> result;
211 while (!content.empty())
214 if (separatorPos == std::string::npos)
216 result.push_back(content);
219 result.push_back(content.substr(0, separatorPos));
220 content = content.substr(separatorPos+1);
225 const std::string RunTimeLibraryLoader::GetPaths()
const
228 const char * envHome = getenv(
"HOME");
229 std::string path = envPath ? envPath :
"";
235 for (
const char ** standardPath=
standardPaths(); *standardPath; standardPath++)
236 path += std::string(path.empty()?
"":
pathSeparator()) + *standardPath;
243 std::string paths=GetPaths();
245 for (
unsigned i=0; i<environmentPaths.size(); i++)
248 std::string fileName = subpathAndName.substr( subpathAndName.rfind(
"/")+1);
250 std::string testDir = environmentPaths[i] +
"/" + subpathAndName.substr(0, subpathAndName.size()-fileName.size());
252 DIR* dir = opendir(testDir.c_str());
258 std::string completeFileName=testDir+fileName;
259 fin.open(completeFileName.c_str(),std::ios::in);
260 if (not fin.is_open())
263 return completeFileName;