summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-14 14:14:22 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-14 14:14:22 +0200
commit0a734819d179f5e89f82cba8917a414ec550e364 (patch)
tree58b457e5ca80deb40069e1311f70d1c56e9a8869
parenta2057d6a815cfe4d4d3a57a375f170f7888bcbf4 (diff)
getFreeDiskSpace: Make compilable for Windows.
-rw-r--r--src/eval.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/eval.zig b/src/eval.zig
index 88c27b7..daf2d38 100644
--- a/src/eval.zig
+++ b/src/eval.zig
@@ -4,10 +4,13 @@ const ArrayList = std.ArrayList;
const Allocator = std.mem.Allocator;
const Thread = std.Thread;
const Mutex = std.Thread.Mutex;
+
const c = @cImport({
- @cInclude("sys/statvfs.h");
@cInclude("errno.h");
@cInclude("stdio.h");
+ if (@import("builtin").os.tag != .windows) {
+ @cInclude("sys/statvfs.h");
+ }
});
const syntax = @import("syntax.zig");
@@ -307,6 +310,7 @@ fn executeCommandWithOutput(command: Command, allocator: Allocator, output_captu
defer allocator.free(path);
const bytes_free = getFreeDiskSpace(path) catch |err| switch (err) {
error.AccessDenied => 0,
+ error.NotImplemented => 0,
};
try output_buffer.writer().print(" {d} File(s) {d:>14} bytes\n", .{ file_count, total_file_bytes });
@@ -1087,11 +1091,18 @@ fn isLeapYear(year: u32) bool {
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0);
}
-fn getFreeDiskSpace(path: []const u8) !u64 {
+const GetFreeDiskSpaceError = error{ NotImplemented, AccessDenied };
+
+fn getFreeDiskSpace(path: []const u8) GetFreeDiskSpaceError!u64 {
+ if (@import("builtin").os.tag == .windows) {
+ return error.NotImplemented;
+ }
+
var stat: c.struct_statvfs = undefined;
if (c.statvfs(path.ptr, &stat) != 0) {
_ = c.perror("statvfs");
return error.AccessDenied;
}
+
return stat.f_bsize * stat.f_bfree;
}