Return result with more error information when opening a shared library fails.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user