zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 446c145ca86b014d6743f5666e9ee1d671b56045 (tree)
parent a2416c685a83788780fec1c379008a2d795f7bd2
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 18 Dec 2025 11:31:23 -0800

std.Io.Threaded: fix compilation errors on posix

Diffstat:
Mlib/std/Io/Dir.zig | 15++++++++++-----
Mlib/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 @@ -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 @@ -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; }