DynLib: Posix fixes

This commit is contained in:
Lynix 2020-02-23 02:17:27 +01:00
parent 364122f582
commit 8ace61ce7d
2 changed files with 17 additions and 17 deletions

View File

@ -10,12 +10,18 @@
namespace Nz
{
DynLibImpl::DynLibImpl(DynLib* parent)
DynLibImpl::DynLibImpl(DynLib*) :
m_handle(nullptr)
{
NazaraUnused(parent);
}
DynLibFunc DynLibImpl::GetSymbol(const String& symbol, String* errorMessage) const
DynLibImpl::~DynLibImpl()
{
if (m_handle)
dlclose(m_handle);
}
DynLibFunc DynLibImpl::GetSymbol(const char* symbol, std::string* errorMessage) const
{
/*
Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction.
@ -31,19 +37,17 @@ namespace Nz
dlerror(); // Clear error flag
converter.pointer = dlsym(m_handle, symbol.GetConstBuffer());
converter.pointer = dlsym(m_handle, symbol);
if (!converter.pointer)
*errorMessage = dlerror();
return converter.func;
}
bool DynLibImpl::Load(const String& libraryPath, String* errorMessage)
bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage)
{
String path = libraryPath;
size_t pos = path.FindLast(".so");
if (pos == String::npos || (path.GetLength() > pos+3 && path[pos+3] != '.'))
std::filesystem::path path = libraryPath;
if (path.extension() != ".so")
path += ".so";
dlerror(); // Clear error flag
@ -57,9 +61,4 @@ namespace Nz
return false;
}
}
void DynLibImpl::Unload()
{
dlclose(m_handle);
}
}

View File

@ -8,6 +8,8 @@
#define NAZARA_DYNLIBIMPL_HPP
#include <Nazara/Core/DynLib.hpp>
#include <filesystem>
#include <string>
namespace Nz
{
@ -19,9 +21,8 @@ namespace Nz
DynLibImpl(DynLib* m_parent);
~DynLibImpl() = default;
DynLibFunc GetSymbol(const String& symbol, String* errorMessage) const;
bool Load(const String& libraryPath, String* errorMessage);
void Unload();
DynLibFunc GetSymbol(const char* symbol, std::string* errorMessage) const;
bool Load(const std::filesystem::path& libraryPath, std::string* errorMessage);
private:
void* m_handle;