diff --git a/hecl/include/HECL/HECL.hpp b/hecl/include/HECL/HECL.hpp index 93b04b108..c4fa0cd63 100644 --- a/hecl/include/HECL/HECL.hpp +++ b/hecl/include/HECL/HECL.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #else #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 @@ -420,6 +421,22 @@ static inline std::string Format(const char* format, ...) return std::string(resultBuf, printSz); } + +static inline bool CheckFreeSpace(const SystemChar* path, size_t reqSz) +{ +#if _WIN32 + ULARGE_INTEGER freeBytes; + if (!GetDiskFreeSpaceExW(path, &freeBytes, nullptr, nullptr)) + LogModule.report(LogVisor::FatalError, "GetDiskFreeSpaceExW %s: %d", path, GetLastError()); + return reqSz < freeBytes; +#else + struct statvfs svfs; + if (statvfs(path, &svfs)) + LogModule.report(LogVisor::FatalError, "statvfs %s: %s", path, strerror(errno)); + return reqSz < svfs.f_bsize * svfs.f_bfree; +#endif +} + static inline int ConsoleWidth() { int retval = 80;