From 232e2a3e28bce56c96c8035cf91d1309d3056389 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 27 Jul 2024 11:32:56 +0200 Subject: [PATCH] Added closeSharedLibrary(). --- source/mijin/util/os.cpp | 10 ++++++++++ source/mijin/util/os.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/source/mijin/util/os.cpp b/source/mijin/util/os.cpp index f3537b9..f483d3e 100644 --- a/source/mijin/util/os.cpp +++ b/source/mijin/util/os.cpp @@ -51,6 +51,16 @@ LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept #endif } +bool closeSharedLibrary(const LibraryHandle library) noexcept +{ +#if MIJIN_TARGET_OS == MIJIN_OS_LINUX + return dlclose(library.data) == 0; +#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS + (void) library; + return true; +#endif +} + void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept { #if MIJIN_TARGET_OS == MIJIN_OS_LINUX diff --git a/source/mijin/util/os.hpp b/source/mijin/util/os.hpp index 616ffc5..297a104 100644 --- a/source/mijin/util/os.hpp +++ b/source/mijin/util/os.hpp @@ -46,6 +46,7 @@ struct LibraryHandle // [[nodiscard]] LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept; +bool closeSharedLibrary(const LibraryHandle library) noexcept; [[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept; void setCurrentThreadName(const char* threadName) noexcept;