diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-12-18 11:31:23 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:10 -0800 |
| commit | 446c145ca86b014d6743f5666e9ee1d671b56045 (patch) | |
| tree | 28b3754371c40a106896916e7e01a5401d9148aa /lib | |
| parent | a2416c685a83788780fec1c379008a2d795f7bd2 (diff) | |
| download | zig-446c145ca86b014d6743f5666e9ee1d671b56045.tar.gz zig-446c145ca86b014d6743f5666e9ee1d671b56045.zip | |
std.Io.Threaded: fix compilation errors on posix
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Io/Dir.zig | 15 | ||||
| -rw-r--r-- | lib/std/Io/Threaded.zig | 4 |
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig index 970cddc82e..0bdaf369c1 100644 --- a/lib/std/Io/Dir.zig +++ b/lib/std/Io/Dir.zig @@ -101,10 +101,8 @@ pub const Reader = struct { /// Fill position of `buffer`. end: usize, - pub const min_buffer_len = switch (native_os) { - .windows => std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), - else => 32, // TODO: what is this based on? - }; + /// A length for `buffer` that allows all implementations to function. + pub const min_buffer_len = std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)); pub const State = enum { /// Indicates the next call to `read` should rewind and start over the @@ -120,6 +118,7 @@ pub const Reader = struct { SystemResources, } || Io.UnexpectedError || Io.Cancelable; + /// Asserts that `buffer` has length at least `min_buffer_len`. pub fn init(dir: Dir, buffer: []align(@alignOf(usize)) u8) Reader { assert(buffer.len >= min_buffer_len); return .{ @@ -164,7 +163,13 @@ pub const Reader = struct { /// see `Walker`. pub const Iterator = struct { reader: Reader, - reader_buffer: [2048]u8 align(@alignOf(usize)), + reader_buffer: [reader_buffer_len]u8 align(@alignOf(usize)), + + pub const reader_buffer_len = 2048; + + comptime { + assert(reader_buffer_len >= Reader.min_buffer_len); + } pub const Error = Reader.Error; diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index fc66345785..10f6c2d507 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -1621,7 +1621,7 @@ fn dirMakePath( // stat the file and return an error if it's not a directory // this is important because otherwise a dangling symlink // could cause an infinite loop - const fstat = dirStatFile(t, dir, component.path, .{}); + const fstat = try dirStatFile(t, dir, component.path, .{}); if (fstat.kind != .directory) return error.NotDir; }, error.FileNotFound => |e| { @@ -3796,7 +3796,7 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D // the remaining unprocessed entries, then backtrack and return what we have so far. if (name_index + std.unicode.calcWtf8Len(name_wtf16le) > unreserved_start + dr.index) { // We should always be able to fit at least one entry into the buffer no matter what - std.debug.assert(buffer_index != 0); + assert(buffer_index != 0); dr.index = backtrack_index; break; } |
