aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-15 16:32:08 +0200
committerMartin Ridgers <[email protected]>2021-09-16 09:34:29 +0200
commit13761b54f48d7d4f0f6982e3726d56345ac1f739 (patch)
treeac230b295a95f7b19f5e85711eba4adc1a3a148c /zencore/filesystem.cpp
parentImplemented PathFromHandle() for Linux (diff)
downloadzen-13761b54f48d7d4f0f6982e3726d56345ac1f739.tar.xz
zen-13761b54f48d7d4f0f6982e3726d56345ac1f739.zip
Implemented GetRunningExecutablePath() for Linux
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 981935c55..4f3ee44b0 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -636,10 +636,23 @@ PathFromHandle(void* NativeHandle)
std::filesystem::path
GetRunningExecutablePath()
{
+#if ZEN_PLATFORM_WINDOWS
TCHAR ExePath[MAX_PATH];
DWORD PathLength = GetModuleFileName(NULL, ExePath, ZEN_ARRAY_COUNT(ExePath));
return {std::wstring_view(ExePath, PathLength)};
+#elif ZEN_PLATFORM_LINUX
+ char Buffer[256];
+ sprintf(Buffer, "/proc/%d/exe", getpid());
+ ssize_t BytesRead = readlink(Buffer, Buffer, sizeof(Buffer) - 1);
+ if (BytesRead < 0)
+ return {};
+
+ Buffer[BytesRead] = '\0';
+ return Buffer;
+#else
+# error Unimplemented platform
+#endif // ZEN_PLATFORM_WINDOWS
}
} // namespace zen