authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-15 16:46:10 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-15 16:46:10 -08:00
log6652f74e3fdd289063b1437643ed7d9c58d5ea90
treec858b48f8e5ee9d47e8ba563bdab9bb320a688f0
parenteb05de73bf3d846d89c75177a6180760b83d434f

add readlinkat


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

mod.zig+14
...@@ -2206,6 +2206,14 @@ pub const libc = struct {...@@ -2206,6 +2206,14 @@ pub const libc = struct {
2206 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/read.html2206 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/read.html
2207 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;2207 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;
22082208
2209 /// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
2210 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/readlink.html
2211 pub extern fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, len: usize) isize;
2212
2213 /// ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
2214 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/readlinkat.html
2215 pub extern fn readlinkat(fd: c_int, noalias path: [*:0]const u8, noalias buf: [*]u8, len: usize) isize;
2216
2209 /// ssize_t recv(int socket, void *buffer, size_t length, int flags);2217 /// ssize_t recv(int socket, void *buffer, size_t length, int flags);
2210 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/recv.html2218 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/recv.html
2211 pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize;2219 pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize;
...@@ -3137,3 +3145,9 @@ pub fn memfd_create(name: [*:0]const u8, flags: c_uint) !c_int {...@@ -3137,3 +3145,9 @@ pub fn memfd_create(name: [*:0]const u8, flags: c_uint) !c_int {
3137 std.debug.assert(rc >= 0);3145 std.debug.assert(rc >= 0);
3138 return rc;3146 return rc;
3139}3147}
3148pub fn readlinkat(dirfd: c_int, noalias path: [*:0]const u8, noalias buf: []u8) ![:0]u8 {
3149 const rc = libc.readlinkat(dirfd, path, buf.ptr, buf.len);
3150 if (rc == -1) return errno.fromInt(errno.fromLibC());
3151 std.debug.assert(rc >= 0);
3152 return buf[0..@intCast(rc) :0];
3153}
test.zig+1
...@@ -29,4 +29,5 @@ test {...@@ -29,4 +29,5 @@ test {
29 _ = &linux.freeaddrinfo;29 _ = &linux.freeaddrinfo;
30 _ = &linux.clock_gettime;30 _ = &linux.clock_gettime;
31 _ = &linux.memfd_create;31 _ = &linux.memfd_create;
32 _ = &linux.readlinkat;
32}33}