authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-16 00:04:54 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-16 00:04:54 -07:00
log506c6f458b9fabc1dd60cf58cee6f15637957b55
treed7e21e78956a1a56455daa499c2e097a67fe0d85
parenta0b5c69b45e4d492c3fcb6681f642e0f628ababd
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add getdents


2 files changed, 21 insertions(+), 0 deletions(-)

mod.zig+20
...@@ -2650,6 +2650,7 @@ pub const libc = struct {...@@ -2650,6 +2650,7 @@ pub const libc = struct {
2650 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;2650 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;
2651 pub extern fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;2651 pub extern fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
2652 pub extern fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize) isize;2652 pub extern fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize) isize;
2653 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;
2653};2654};
26542655
2655pub const clock_t = c_long;2656pub const clock_t = c_long;
...@@ -2694,6 +2695,7 @@ pub const struct_sockaddr_in = extern struct { family: AF = .INET, port: in_port...@@ -2694,6 +2695,7 @@ pub const struct_sockaddr_in = extern struct { family: AF = .INET, port: in_port
2694pub const struct_sockaddr_in6 = extern struct { family: AF = .INET6, port: in_port_t, flowinfo: u32, addr: struct_in6_addr, scope_id: u32 };2695pub const struct_sockaddr_in6 = extern struct { family: AF = .INET6, port: in_port_t, flowinfo: u32, addr: struct_in6_addr, scope_id: u32 };
2695pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8 };2696pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8 };
2696pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo };2697pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo };
2698pub const struct_dirent = extern struct { ino: ino_t, off: off_t, reclen: c_ushort, type: DT, name: [NAME_MAX + 1]u8 };
26972699
2698pub const AT = struct {2700pub const AT = struct {
2699 pub const FDCWD = -100;2701 pub const FDCWD = -100;
...@@ -3028,6 +3030,18 @@ pub const SO = struct {...@@ -3028,6 +3030,18 @@ pub const SO = struct {
3028 pub const DOMAIN = 39;3030 pub const DOMAIN = 39;
3029};3031};
30303032
3033pub const DT = enum(u8) {
3034 UNKNOWN = 0,
3035 FIFO = 1,
3036 CHR = 2,
3037 DIR = 4,
3038 BLK = 6,
3039 REG = 8,
3040 LNK = 10,
3041 SOCK = 12,
3042 WHT = 14,
3043};
3044
3031pub fn getpid() pid_t {3045pub fn getpid() pid_t {
3032 return libc.getpid();3046 return libc.getpid();
3033}3047}
...@@ -3188,3 +3202,9 @@ pub fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize...@@ -3188,3 +3202,9 @@ pub fn sendfile(out_fd: c_int, in_fd: c_int, offset: ?*const off_t, count: usize
3188 std.debug.assert(rc >= 0);3202 std.debug.assert(rc >= 0);
3189 return @intCast(rc);3203 return @intCast(rc);
3190}3204}
3205pub fn getdents(dirfd: c_int, buf: []u8) errno.Error!usize {
3206 const rc = libc.getdents(dirfd, buf.ptr, buf.len);
3207 if (rc == -1) return errno.fromInt(errno.fromLibC());
3208 std.debug.assert(rc >= 0);
3209 return @intCast(rc);
3210}
test.zig+1
...@@ -34,4 +34,5 @@ test {...@@ -34,4 +34,5 @@ test {
34 _ = &linux.writev;34 _ = &linux.writev;
35 _ = &linux.getsockname;35 _ = &linux.getsockname;
36 _ = &linux.sendfile;36 _ = &linux.sendfile;
37 _ = &linux.getdents;
37}38}