#ifndef NSTD_OS_UNIX_SHARED_LIB_H #define NSTD_OS_UNIX_SHARED_LIB_H #include "../../core/optional.h" #include "../../nstd.h" /// Represents an owned handle to a dynamically loaded library. typedef struct { /// A raw handle to the shared library. NSTDAnyMut handle; } NSTDUnixSharedLib; /// Represents an optional `NSTDUnixSharedLib`. NSTDOptional(NSTDUnixSharedLib) NSTDUnixOptionalSharedLib; /// Loads a dynamically loaded shared library. /// /// # Parameters: /// /// - `const NSTDChar *path` - A path to the shared library to load. /// /// # Returns /// /// `NSTDUnixOptionalSharedLib lib` - A handle to the loaded library. /// /// # Safety /// /// See . NSTDAPI NSTDUnixOptionalSharedLib nstd_os_unix_shared_lib_load(const NSTDChar *path); /// Returns a raw handle to a dynamically loaded library. /// /// # Parameters: /// /// - `const NSTDUnixSharedLib *lib` - The shared library. /// /// # Returns /// /// `NSTDAnyMut handle` - A raw handle to the dynamically loaded library. NSTDAPI NSTDAnyMut nstd_os_unix_shared_lib_handle(const NSTDUnixSharedLib *lib); /// Returns an immutable opaque pointer to a symbol in a loaded library. /// /// # Parameters: /// /// - `const NSTDUnixSharedLib *lib` - The shared library. /// /// - `const NSTDChar *symbol` - The symbol to retrieve a pointer to. /// /// # Returns /// /// `NSTDAny ptr` - A pointer to the loaded symbol, null on error. /// /// # Safety /// /// See . NSTDAPI NSTDAny nstd_os_unix_shared_lib_get(const NSTDUnixSharedLib *lib, const NSTDChar *symbol); /// Returns a mutable opaque pointer to a symbol in a loaded library. /// /// # Parameters: /// /// - `NSTDUnixSharedLib *lib` - The shared library. /// /// - `const NSTDChar *symbol` - The symbol to retrieve a pointer to. /// /// # Returns /// /// `NSTDAnyMut ptr` - A pointer to the loaded symbol, null on error. /// /// # Safety /// /// See . NSTDAPI NSTDAnyMut nstd_os_unix_shared_lib_get_mut(NSTDUnixSharedLib *lib, const NSTDChar *symbol); /// Closes and frees a loaded shared library. /// /// # Parameters: /// /// - `NSTDUnixSharedLib lib` - A handle to the loaded library to unload. /// /// # Safety /// /// See . NSTDAPI void nstd_os_unix_shared_lib_free(NSTDUnixSharedLib lib); #endif