diff options
| author | Stefan Boberg <[email protected]> | 2023-05-09 17:19:57 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-09 17:19:57 +0200 |
| commit | 835f14403d5f6e04d65b761857ee1271a4e7fe98 (patch) | |
| tree | 4a5b69325e7b468e1fdabc2bfd296f4e0b647175 /src/zencore/filesystem.cpp | |
| parent | fixed merge error (diff) | |
| download | zen-835f14403d5f6e04d65b761857ee1271a4e7fe98.tar.xz zen-835f14403d5f6e04d65b761857ee1271a4e7fe98.zip | |
add context to MapViewOfFile errors (#282)
* added FileSizeFromHandle function
* added file size to error message when MapViewOfFile fails
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() { |