mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-13 20:21:48 +00:00
fix: use platform specific calls to get executable dir
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
27
src/Utils/Utils/PathUtils.cpp
Normal file
27
src/Utils/Utils/PathUtils.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "PathUtils.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string GetExecutablePath()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char result[MAX_PATH];
|
||||
return std::string(result, GetModuleFileNameA(NULL, result, MAX_PATH));
|
||||
#elif defined(__linux__)
|
||||
char result[PATH_MAX];
|
||||
const auto count = readlink("/proc/self/exe", result, PATH_MAX);
|
||||
return std::string(result, (count > 0) ? count : 0);
|
||||
#else
|
||||
throw std::runtime_error("Unknown platform for executable path");
|
||||
#endif
|
||||
}
|
||||
} // namespace utils
|
||||
8
src/Utils/Utils/PathUtils.h
Normal file
8
src/Utils/Utils/PathUtils.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string GetExecutablePath();
|
||||
}
|
||||
Reference in New Issue
Block a user