2
0
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:
Jan
2025-04-20 17:07:04 +02:00
parent 199446b09f
commit fb20cbf81c
5 changed files with 41 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#include <cstdint>
#include <set>
#include <string>

View 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

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace utils
{
std::string GetExecutablePath();
}