From 64ddba955a1f98ab77cfb39844a09f472ebc4609 Mon Sep 17 00:00:00 2001 From: Michael Dusan Date: Thu, 15 Jun 2023 14:48:19 -0400 Subject: [PATCH] freebsd: fix std.c.getdents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fix getdents return type usize → isize - usize ultimately forced errors to .SUCCESS in std.c.getError New behavior in freebsd 13.2 is to return ENOENT if the directory being iterated is deleted during iteration. We now detect this and treat it consistent with iteration ending. --- lib/std/c/freebsd.zig | 2 +- lib/std/fs.zig | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index b3e6c6769ac0964cab514faa42d386d9da4bfb57..b351128b0324f105e04090a66986c0857215be19 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -75,7 +75,7 @@ pub const _errno = __error; pub extern "c" var malloc_options: [*:0]const u8; -pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; +pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize; pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; pub extern "c" fn getentropy(buf_ptr: [*]u8, buf_len: usize) c_int; diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 38b94873e6213efdb1f69a8aa2205c2fec757024..bb0890be4ba7ba7fdf53991b922f48fc8292317f 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -478,6 +478,9 @@ pub const IterableDir = struct { .FAULT => unreachable, .NOTDIR => unreachable, .INVAL => unreachable, + // Introduced in freebsd 13.2: directory unlinked but still open. + // To be consistent, iteration ends if the directory being iterated is deleted during iteration. + .NOENT => return null, else => |err| return os.unexpectedErrno(err), } if (rc == 0) return null; -- 2.54.0