diff options
Diffstat (limited to 'zencore/filesystem.cpp')
| -rw-r--r-- | zencore/filesystem.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 1e4a52638..a2442a134 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -976,19 +976,27 @@ PathFromHandle(void* NativeHandle) } }; - DWORD RequiredLengthIncludingNul = GetFinalPathNameByHandleWRetry(NativeHandle, nullptr, 0, FILE_NAME_OPENED); + static const DWORD PathDataSize = 512; + wchar_t PathData[PathDataSize]; + DWORD RequiredLengthIncludingNul = GetFinalPathNameByHandleWRetry(NativeHandle, PathData, PathDataSize, FILE_NAME_OPENED); if (RequiredLengthIncludingNul == 0) { ThrowLastError(fmt::format("failed to get path from file handle {}", NativeHandle)); } + if (RequiredLengthIncludingNul < PathDataSize) + { + std::wstring FullPath(PathData, gsl::narrow<size_t>(RequiredLengthIncludingNul)); + return FullPath; + } + std::wstring FullPath; FullPath.resize(RequiredLengthIncludingNul - 1); const DWORD FinalLength = GetFinalPathNameByHandleWRetry(NativeHandle, FullPath.data(), RequiredLengthIncludingNul, FILE_NAME_OPENED); ZEN_UNUSED(FinalLength); - return FullPath; + #elif ZEN_PLATFORM_LINUX char Link[PATH_MAX]; char Path[64]; |