authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-18 07:34:32+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-18 07:34:32+02:00
log9636d76b6d26d142f7d23e6d25eec1c28cf571b4
tree8b9fd1906c87592d136075d390a37f9228043e33
parent21914c7c01d8d1071034153451414719906167b8

std.os.linux: getdents accepts a c_uint length (#31825)

https://github.com/torvalds/linux/blob/e774d5f1bc27a85f858bce7688509e866f8e8a4e/include/linux/syscalls.h#L1100-L1102 https://github.com/torvalds/linux/blob/e774d5f1bc27a85f858bce7688509e866f8e8a4e/include/linux/syscalls.h#L477-L479 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31825 Reviewed-by: Andrew Kelley <andrew@ziglang.org> Co-authored-by: Meghan Denny <hello@nektro.net> Co-committed-by: Meghan Denny <hello@nektro.net>

3 files changed, 6 insertions(+), 6 deletions(-)

lib/std/Io/Threaded.zig+1-1
...@@ -5484,7 +5484,7 @@ fn dirReadLinux(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir...@@ -5484,7 +5484,7 @@ fn dirReadLinux(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir
5484 }5484 }
5485 const syscall: Syscall = try .start();5485 const syscall: Syscall = try .start();
5486 const n = while (true) {5486 const n = while (true) {
5487 const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, dr.buffer.len);5487 const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, @min(dr.buffer.len, std.math.maxInt(c_uint)));
5488 switch (linux.errno(rc)) {5488 switch (linux.errno(rc)) {
5489 .SUCCESS => {5489 .SUCCESS => {
5490 syscall.finish();5490 syscall.finish();
lib/std/Io/Uring.zig+1-1
...@@ -3070,7 +3070,7 @@ fn dirRead(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Read...@@ -3070,7 +3070,7 @@ fn dirRead(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Read
3070 }3070 }
3071 const n = while (true) {3071 const n = while (true) {
3072 try sync.cancel_region.await(.nothing);3072 try sync.cancel_region.await(.nothing);
3073 const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, dr.buffer.len);3073 const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, @min(dr.buffer.len, std.math.maxInt(c_uint)));
3074 switch (linux.errno(rc)) {3074 switch (linux.errno(rc)) {
3075 .SUCCESS => break rc,3075 .SUCCESS => break rc,
3076 .INTR => {},3076 .INTR => {},
lib/std/os/linux.zig+4-4
...@@ -887,21 +887,21 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {...@@ -887,21 +887,21 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
887 return syscall2(.getcwd, @intFromPtr(buf), size);887 return syscall2(.getcwd, @intFromPtr(buf), size);
888}888}
889889
890pub fn getdents(fd: fd_t, dirp: [*]u8, len: usize) usize {890pub fn getdents(fd: fd_t, dirp: [*]u8, len: c_uint) usize {
891 return syscall3(891 return syscall3(
892 .getdents,892 .getdents,
893 @as(u32, @bitCast(fd)),893 @as(u32, @bitCast(fd)),
894 @intFromPtr(dirp),894 @intFromPtr(dirp),
895 @min(len, maxInt(c_int)),895 len,
896 );896 );
897}897}
898898
899pub fn getdents64(fd: fd_t, dirp: [*]u8, len: usize) usize {899pub fn getdents64(fd: fd_t, dirp: [*]u8, len: c_uint) usize {
900 return syscall3(900 return syscall3(
901 .getdents64,901 .getdents64,
902 @as(u32, @bitCast(fd)),902 @as(u32, @bitCast(fd)),
903 @intFromPtr(dirp),903 @intFromPtr(dirp),
904 @min(len, maxInt(c_int)),904 len,
905 );905 );
906}906}
907907