ENH: add dlSymFound() to check for existence of symbol without warnings

This commit is contained in:
Mark Olesen 2011-02-25 18:19:45 +01:00
parent b8f643f3da
commit f2ff53f7b4
2 changed files with 24 additions and 1 deletions

View File

@ -1106,4 +1106,24 @@ void* Foam::dlSym(void* handle, const std::string& symbol)
}
bool Foam::dlSymFound(void* handle, const std::string& symbol)
{
if (handle && !symbol.empty())
{
// clear any old errors - see manpage dlopen
(void) ::dlerror();
// get address of symbol
(void) ::dlsym(handle, symbol.c_str());
// symbol can be found if there was no error
return !::dlerror();
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -190,9 +190,12 @@ void* dlOpen(const fileName& lib);
//- Close a dlopened library using handle. Return true if successful
bool dlClose(void*);
//- Lookup a symbol in a dlopened library using handle
//- Lookup a symbol in a dlopened library using handle to library
void* dlSym(void* handle, const std::string& symbol);
//- Report if symbol in a dlopened library could be found
bool dlSymFound(void* handle, const std::string& symbol);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //