From f2ff53f7b4e434035f25fd83fc71d0d0decc3e30 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 25 Feb 2011 18:19:45 +0100 Subject: [PATCH] ENH: add dlSymFound() to check for existence of symbol without warnings --- src/OSspecific/POSIX/POSIX.C | 20 ++++++++++++++++++++ src/OpenFOAM/include/OSspecific.H | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 43168336e6..e6e54c32c0 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -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; + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 38b0d14a10..d68ae1661d 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -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); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //