Add CheckFreeSpace function

This commit is contained in:
Jack Andersen 2016-01-24 16:16:40 -10:00
parent aee526fb8e
commit 9109abef31
1 changed files with 17 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/statvfs.h>
#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;