diff options
Diffstat (limited to 'src/zencore/filesystem.cpp')
| -rw-r--r-- | src/zencore/filesystem.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index a17773024..8a6a9869c 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -1022,6 +1022,27 @@ PathFromHandle(void* NativeHandle) #endif // ZEN_PLATFORM_WINDOWS } +uint64_t +FileSizeFromHandle(void* NativeHandle) +{ + uint64_t FileSize = ~0ull; + +#if ZEN_PLATFORM_WINDOWS + BY_HANDLE_FILE_INFORMATION Bhfh = {}; + if (GetFileInformationByHandle(NativeHandle, &Bhfh)) + { + FileSize = uint64_t(Bhfh.nFileSizeHigh) << 32 | Bhfh.nFileSizeLow; + } +#else + int Fd = int(intptr_t(NativeHandle)); + struct stat Stat; + fstat(Fd, &Stat); + FileSize = size_t(Stat.st_size); +#endif + + return FileSize; +} + std::filesystem::path GetRunningExecutablePath() { |