Added getExecutablePath(). Still need to check if the Windows version works, but who cares?
This commit is contained in:
parent
75398b89d5
commit
461d3ec694
@ -8,7 +8,9 @@
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
// TODO
|
||||
#include <array>
|
||||
#include <windows.h>
|
||||
#include "../util/winundef.hpp"
|
||||
#endif
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
@ -97,6 +99,34 @@ void setCurrentThreadName(const char* threadName) MIJIN_NOEXCEPT
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string getExecutablePath() MIJIN_NOEXCEPT
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
return fs::canonical("/proc/self/exe").string();
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
// TODO: this is completely untested
|
||||
std::array<char, 1024> buffer;
|
||||
if (FAILED(GetModuleFileNameA(nullptr, buffer.data(), buffer.size())))
|
||||
{
|
||||
std::vector<char> buffer2;
|
||||
buffer2.resize(1024);
|
||||
do
|
||||
{
|
||||
if (buffer2.size() >= 10240)
|
||||
{
|
||||
MIJIN_ERROR("Something is wrong.");
|
||||
return "";
|
||||
}
|
||||
buffer2.resize(buffer2.size() + 1024);
|
||||
}
|
||||
while (FAILED(GetModuleFileNameA(nullptr, buffer.data(), buffer.size())));
|
||||
return buffer2.data();
|
||||
}
|
||||
return buffer.data();
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) MIJIN_NOEXCEPT
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
|
@ -77,6 +77,7 @@ public:
|
||||
bool closeSharedLibrary(const LibraryHandle library) MIJIN_NOEXCEPT;
|
||||
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) MIJIN_NOEXCEPT;
|
||||
void setCurrentThreadName(const char* threadName) MIJIN_NOEXCEPT;
|
||||
[[nodiscard]] std::string getExecutablePath() MIJIN_NOEXCEPT;
|
||||
|
||||
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) MIJIN_NOEXCEPT;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user