summaryrefslogtreecommitdiff
path: root/src/statvfs_helper.c
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-24 06:33:50 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-24 06:33:50 +0200
commit65bdefaf7a0e0299e2a4361d107a9721eac9dd4e (patch)
treeb605c47cb1ca162b1bd9893784938b43bc343f4c /src/statvfs_helper.c
parent16e6d5386fecba7895aa64c035eabec664472de6 (diff)
Handle statvfs in C.
This is necessary for musl support because musl's version of struct statvfs contains bitfields, which Zig does not know how to import.
Diffstat (limited to 'src/statvfs_helper.c')
-rw-r--r--src/statvfs_helper.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/statvfs_helper.c b/src/statvfs_helper.c
new file mode 100644
index 0000000..8f6a4fe
--- /dev/null
+++ b/src/statvfs_helper.c
@@ -0,0 +1,19 @@
+#include <stdint.h>
+
+#ifdef _WIN32
+uint64_t statvfs_get_free_space_impl(const char* path) {
+ // Windows not implemented
+ (void)path;
+ return 0;
+}
+#else
+#include <sys/statvfs.h>
+
+uint64_t statvfs_get_free_space_impl(const char* path) {
+ struct statvfs stat;
+ if (statvfs(path, &stat) != 0) {
+ return 0;
+ }
+ return (uint64_t)stat.f_frsize * (uint64_t)stat.f_bavail;
+}
+#endif \ No newline at end of file