diff --git a/mod.zig b/mod.zig index 6464ee78b737fba0cb797b3f346bc67527b92e85..46217962ad1e3ee95474fd98f94f3ae0c50df034 100644 --- a/mod.zig +++ b/mod.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const builtin = @import("builtin"); const linux = std.os.linux; +const builtin = @import("builtin"); comptime { std.debug.assert(builtin.target.os.tag == .linux); @@ -2781,6 +2781,21 @@ pub const libc = struct { pub extern fn futimens(fd: c_int, times: *const [2]struct_timespec) c_int; }; +comptime { + const C = struct { + fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) callconv(.c) c_int { + const rc = std.os.linux.syscall3(.getdents64, @intCast(dirfd), @intFromPtr(buf), nbytes); + const signed_r: isize = @bitCast(rc); + if (signed_r < 0 and signed_r > -4096) { + libc.__errno_location().* = @intCast(-signed_r); + return -1; + } + return @intCast(rc); + } + }; + if (builtin.abi.isGnu()) @export(&C.getdents, .{ .name = "getdents", .linkage = .weak }); // glibc chooses to only expose this as getdents64 +} + pub const clock_t = c_long; pub const pid_t = c_int; pub const gid_t = c_uint;