summaryrefslogtreecommitdiff
path: root/src/statvfs_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statvfs_helper.c')
-rw-r--r--src/statvfs_helper.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/statvfs_helper.c b/src/statvfs_helper.c
index 8f6a4fe..b22d2d1 100644
--- a/src/statvfs_helper.c
+++ b/src/statvfs_helper.c
@@ -1,9 +1,41 @@
#include <stdint.h>
#ifdef _WIN32
+#include <windows.h>
+#include <string.h>
+#include <stdio.h>
+
uint64_t statvfs_get_free_space_impl(const char* path) {
- // Windows not implemented
- (void)path;
+ ULARGE_INTEGER freeBytesAvailable;
+ ULARGE_INTEGER totalNumberOfBytes;
+ ULARGE_INTEGER totalNumberOfFreeBytes;
+
+ // GetDiskFreeSpaceExA expects a directory path, so we need to extract the root directory
+ // For simplicity, we'll use the current directory if path is a file
+ char root_path[MAX_PATH];
+
+ // If path is already a root (like "C:" or "C:\"), use it directly
+ if (strlen(path) >= 2 && path[1] == ':') {
+ snprintf(root_path, sizeof(root_path), "%c:\\", path[0]);
+ } else {
+ // For relative paths or files, get the current directory
+ if (GetCurrentDirectoryA(sizeof(root_path), root_path) == 0) {
+ return 0;
+ }
+ // Ensure it ends with backslash for GetDiskFreeSpaceExA
+ size_t len = strlen(root_path);
+ if (len > 0 && root_path[len - 1] != '\\') {
+ if (len < sizeof(root_path) - 1) {
+ root_path[len] = '\\';
+ root_path[len + 1] = '\0';
+ }
+ }
+ }
+
+ if (GetDiskFreeSpaceExA(root_path, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes)) {
+ return (uint64_t)freeBytesAvailable.QuadPart;
+ }
+
return 0;
}
#else
@@ -16,4 +48,4 @@ uint64_t statvfs_get_free_space_impl(const char* path) {
}
return (uint64_t)stat.f_frsize * (uint64_t)stat.f_bavail;
}
-#endif \ No newline at end of file
+#endif