aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-12-15 10:07:38 +0100
committerMartin Ridgers <[email protected]>2021-12-15 10:07:38 +0100
commitd019db12dfc866e741e7775ce5becdf24cfc6c1a (patch)
treea5cb4f54129b1a7c01dea8894e52b1bb9623d651 /zencore/filesystem.cpp
parentstd::fs::path cannot be forward declared (diff)
downloadzen-d019db12dfc866e741e7775ce5becdf24cfc6c1a.tar.xz
zen-d019db12dfc866e741e7775ce5becdf24cfc6c1a.zip
Implemented DiskSpaceInfo() for POSIX platforms
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index f850f1a80..7c55be3e8 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -22,6 +22,7 @@
# include <dirent.h>
# include <fcntl.h>
# include <sys/stat.h>
+# include <sys/statvfs.h>
# include <unistd.h>
#endif
@@ -762,16 +763,19 @@ DiskSpaceInfo(std::filesystem::path Directory, std::error_code& Error)
{
return {.Free = static_cast<uint64_t>(Free.QuadPart), .Total = static_cast<uint64_t>(Total.QuadPart)};
}
- else
+#else
+ struct statvfs Stat;
+ if (statvfs(Directory.c_str(), &Stat) == 0)
{
- Error = std::error_code(::GetLastError(), std::system_category());
- return {};
+ return {
+ .Free = uint64_t(Stat.f_bsize * Stat.f_bavail),
+ .Total = uint64_t(Stat.f_frsize * Stat.f_blocks),
+ };
}
-#else
- ZEN_ERROR("DiskSpaceInfo() is not implemented on this platform");
- Error = std::error_code(1, std::system_category());
- return {};
#endif
+
+ Error = std::error_code(zen::GetLastError(), std::system_category());
+ return {};
}
void