authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-09 15:33:59 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-09 15:33:59 -07:00
logaa86e0d87f9fd0678af59e92f018cd9d698742c2
treefb0fd2d33ff6d18752fe9ccab87dd3cdc322bb4c
parent1d4b3cc3a4a2d7847b607caf3914d1efd2588850
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

expose getdents on glibc


1 files changed, 16 insertions(+), 1 deletions(-)

mod.zig+16-1
......@@ -1,6 +1,6 @@
11const std = @import("std");
2const builtin = @import("builtin");
32const linux = std.os.linux;
3const builtin = @import("builtin");
44
55comptime {
66 std.debug.assert(builtin.target.os.tag == .linux);
......@@ -2781,6 +2781,21 @@ pub const libc = struct {
27812781 pub extern fn futimens(fd: c_int, times: *const [2]struct_timespec) c_int;
27822782};
27832783
2784comptime {
2785 const C = struct {
2786 fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) callconv(.c) c_int {
2787 const rc = std.os.linux.syscall3(.getdents64, @intCast(dirfd), @intFromPtr(buf), nbytes);
2788 const signed_r: isize = @bitCast(rc);
2789 if (signed_r < 0 and signed_r > -4096) {
2790 libc.__errno_location().* = @intCast(-signed_r);
2791 return -1;
2792 }
2793 return @intCast(rc);
2794 }
2795 };
2796 if (builtin.abi.isGnu()) @export(&C.getdents, .{ .name = "getdents", .linkage = .weak }); // glibc chooses to only expose this as getdents64
2797}
2798
27842799pub const clock_t = c_long;
27852800pub const pid_t = c_int;
27862801pub const gid_t = c_uint;