diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-08-06 16:19:40 +0200 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-08-06 16:19:40 +0200 |
| commit | b9c0e8f9f8b3148e7ffc95b4eaf25299d9ead2a2 (patch) | |
| tree | e51067a3a4019221cabf5b710742d14f948b5310 /src/Daemon/DynamicLibrary.cpp | |
| parent | 84348ccea878d509f838927e1bf393e5443d3ac8 (diff) | |
| parent | b64e1671afd1cd1c25604ffb3bf6f681a864b639 (diff) | |
| download | abrt-b9c0e8f9f8b3148e7ffc95b4eaf25299d9ead2a2.tar.gz abrt-b9c0e8f9f8b3148e7ffc95b4eaf25299d9ead2a2.tar.xz abrt-b9c0e8f9f8b3148e7ffc95b4eaf25299d9ead2a2.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/Daemon/DynamicLibrary.cpp')
| -rw-r--r-- | src/Daemon/DynamicLibrary.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Daemon/DynamicLibrary.cpp b/src/Daemon/DynamicLibrary.cpp new file mode 100644 index 0000000..ffb2a6e --- /dev/null +++ b/src/Daemon/DynamicLibrary.cpp @@ -0,0 +1,59 @@ +/* + DynamicLybrary.cpp + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "DynamicLibrary.h" +#include "ABRTException.h" +#include <iostream> +#include <dlfcn.h> + +CDynamicLibrary::CDynamicLibrary(const std::string& pPath) : + m_pHandle(NULL) +{ + Load(pPath); +} + +CDynamicLibrary::~CDynamicLibrary() +{ + if (m_pHandle != NULL) + { + dlclose(m_pHandle); + m_pHandle = NULL; + } +} + +void CDynamicLibrary::Load(const std::string& pPath) +{ + m_pHandle = dlopen(pPath.c_str(), RTLD_NOW); + if (m_pHandle == NULL) + { + throw CABRTException(EXCEP_DL, "CDynamicLibrary::Load(): Cannot load " + pPath + " : " + std::string(dlerror())); + } +} + +void* CDynamicLibrary::FindSymbol(const std::string& pName) +{ + void* sym = dlsym(m_pHandle, pName.c_str()); + if (sym == NULL) + { + throw CABRTException(EXCEP_DL, "CDynamicLibrary::Load(): Cannot find symbol '" + pName + "'"); + } + return sym; +} |
