Return result with more error information when opening a shared library fails.

This commit is contained in:
2024-07-29 21:48:04 +02:00
parent a9a85aecdf
commit f6f77f6dc1
4 changed files with 29 additions and 8 deletions

View File

@@ -39,11 +39,18 @@ namespace mijin
// public functions
//
LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept
Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
dlerror();
const fs::path libraryPath = fs::absolute(libraryFile);
return {.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
void* ptr = dlopen(libraryPath.c_str(), RTLD_NOW);
if (ptr == nullptr)
{
return ResultError(dlerror());
}
return LibraryHandle{.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
// TODO
(void) libraryFile;