aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-15 16:29:45 +0200
committerMartin Ridgers <[email protected]>2021-09-16 09:34:29 +0200
commit74ef06cb92d18079f5733083307e508efc85b9b3 (patch)
tree01c7a8f70e1fc5689eebd13c6fb913c0498104db /zencore/filesystem.cpp
parentIncorrect fmt format syntax causing compile errors with GCC (diff)
downloadzen-74ef06cb92d18079f5733083307e508efc85b9b3.tar.xz
zen-74ef06cb92d18079f5733083307e508efc85b9b3.zip
Implemented PathFromHandle() 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 329cc241d..981935c55 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -605,6 +605,7 @@ FileSystemTraversal::TraverseFileSystem(const std::filesystem::path& RootDir, Tr
std::filesystem::path
PathFromHandle(void* NativeHandle)
{
+#if ZEN_PLATFORM_WINDOWS
if (NativeHandle == nullptr || NativeHandle == INVALID_HANDLE_VALUE)
{
return std::filesystem::path();
@@ -618,6 +619,18 @@ PathFromHandle(void* NativeHandle)
const DWORD FinalLength = GetFinalPathNameByHandleW(NativeHandle, FullPath.data(), RequiredLengthIncludingNul, FILE_NAME_OPENED);
return FullPath;
+#elif ZEN_PLATFORM_LINUX
+ char Buffer[256];
+ sprintf(Buffer, "/proc/%d/fd/%d", getpid(), int(uintptr_t(NativeHandle)));
+ ssize_t BytesRead = readlink(Buffer, Buffer, sizeof(Buffer) - 1);
+ if (BytesRead <= 0)
+ return std::filesystem::path();
+
+ Buffer[BytesRead] = '\0';
+ return Buffer;
+#else
+# error Unimplemented platform
+#endif // ZEN_PLATFORM_WINDOWS
}
std::filesystem::path