39 lines
633 B
C++
39 lines
633 B
C++
#include "dl.hpp"
|
|
|
|
#include <string>
|
|
#include <dlfcn.h>
|
|
|
|
DL::DL(DL&& other) noexcept {
|
|
m_handle = other.m_handle;
|
|
other.m_handle = nullptr;
|
|
}
|
|
|
|
DL& DL::operator=(DL&& other) noexcept {
|
|
if (this == &other)
|
|
return *this;
|
|
|
|
m_handle = other.m_handle;
|
|
other.m_handle = nullptr;
|
|
return *this;
|
|
}
|
|
|
|
DL::DL(const std::filesystem::path& dl) : m_handle{ nullptr } {
|
|
m_handle = dlopen(dl.c_str(), RTLD_NOW);
|
|
}
|
|
|
|
DL::~DL() {
|
|
if (m_handle)
|
|
dlclose(m_handle);
|
|
}
|
|
|
|
void* DL::resolve(const char* symbol) const {
|
|
if (!m_handle)
|
|
return nullptr;
|
|
|
|
return dlsym(m_handle, symbol);
|
|
}
|
|
|
|
DL::operator bool() const {
|
|
return m_handle != nullptr;
|
|
}
|