forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiskspace.cpp
More file actions
39 lines (27 loc) · 831 Bytes
/
diskspace.cpp
File metadata and controls
39 lines (27 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "diskspace.h"
namespace bf = boost::filesystem;
#if !defined(_MSC_VER)
#include <sys/statvfs.h>
#include <cerrno>
namespace cpputils {
uint64_t free_disk_space_in_bytes(const bf::path& location) {
struct statvfs stat {};
int result = ::statvfs(location.string().c_str(), &stat);
if (0 != result) {
throw std::runtime_error("Error calling statvfs(). Errno: " + std::to_string(errno));
}
return stat.f_frsize*stat.f_bavail;
}
}
#else
#include <Windows.h>
namespace cpputils {
uint64_t free_disk_space_in_bytes(const bf::path& location) {
ULARGE_INTEGER freeBytes;
if (!GetDiskFreeSpaceEx(location.string().c_str(), &freeBytes, nullptr, nullptr)) {
throw std::runtime_error("Error calling GetDiskFreeSpaceEx(). Error code: " + std::to_string(GetLastError()));
}
return freeBytes.QuadPart;
}
}
#endif