87 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
 | 
						|
#include "os.hpp"
 | 
						|
 | 
						|
#include <filesystem>
 | 
						|
#include "../detect.hpp"
 | 
						|
 | 
						|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
 | 
						|
    #include <dlfcn.h>
 | 
						|
    #include <pthread.h>
 | 
						|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
 | 
						|
// TODO
 | 
						|
#endif
 | 
						|
 | 
						|
namespace fs = std::filesystem;
 | 
						|
 | 
						|
namespace mijin
 | 
						|
{
 | 
						|
 | 
						|
//
 | 
						|
// internal defines
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// internal constants
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// internal types
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// internal variables
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// internal functions
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// public functions
 | 
						|
//
 | 
						|
 | 
						|
LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept
 | 
						|
{
 | 
						|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
 | 
						|
    const fs::path libraryPath = fs::absolute(libraryFile);
 | 
						|
    return {.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
 | 
						|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
 | 
						|
	// TODO
 | 
						|
	(void) libraryFile;
 | 
						|
	return {};
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept
 | 
						|
{
 | 
						|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
 | 
						|
    return dlsym(library.data, symbolName);
 | 
						|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
 | 
						|
	(void) library;
 | 
						|
	(void) symbolName;
 | 
						|
	return nullptr;
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
void setCurrentThreadName(const char* threadName) noexcept
 | 
						|
{
 | 
						|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
 | 
						|
    pthread_setname_np(pthread_self(), threadName);
 | 
						|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
 | 
						|
	(void) threadName;
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept
 | 
						|
{
 | 
						|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
 | 
						|
    return "lib" + std::string(libraryName) + ".so";
 | 
						|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
 | 
						|
    return std::string(libraryName) + ".dll";
 | 
						|
#else
 | 
						|
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
} // namespace mijin
 |