From 74ef06cb92d18079f5733083307e508efc85b9b3 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 16:29:45 +0200 Subject: Implemented PathFromHandle() for Linux --- zencore/filesystem.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'zencore/filesystem.cpp') 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 -- cgit v1.2.3