From 08335841bee19460f40e1c6b2104d5dd56540dd2 Mon Sep 17 00:00:00 2001 From: Justin Kinnaird Date: Tue, 10 Dec 2019 03:22:53 -0600 Subject: [PATCH] Use platform-specific methods for exePath --- es-core/src/utils/FileSystemUtil.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index a30d0ca2d..0ca06b59b 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -194,8 +194,21 @@ namespace Utils void setExePath(const std::string& _path) { - exePath = getCanonicalPath(_path); + constexpr int path_max = 32767; +#if defined(_WIN32) + std::wstring result(path_max, 0); + if(GetModuleFileNameW(nullptr, &result[0], path_max) != 0) + exePath = convertFromWideString(result); +#else + std::string result(path_max, 0); + if(readlink("/proc/self/exe", &result[0], path_max) != -1) + exePath = result; +#endif + exePath = getCanonicalPath(exePath); + // Fallback to argv[0] if everything else fails + if (exePath.empty()) + exePath = getCanonicalPath(_path); if(isRegularFile(exePath)) exePath = getParent(exePath);