diff options
-rw-r--r-- | src/eval.zig | 15 |
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; } |