From 1801d0cdde61ac06001a9722cb61e0214d937305 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 28 Dec 2025 22:20:26 -0800 Subject: [PATCH] add fstatat --- mod.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mod.zig b/mod.zig index 6559e8b755746c6e11ccd366c24705bb4f720efb..5677454ed8ec37e71a0c889c2b1c6dd47e0a52aa 100644 --- a/mod.zig +++ b/mod.zig @@ -1334,6 +1334,10 @@ pub const libc = struct { /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/fstat.html pub extern fn fstat(fd: c_int, buf: *struct_stat) c_int; + /// int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); + /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/fstatat.html + pub extern fn fstatat(fd: c_int, noalias path: [*:0]const u8, noalias buf: *struct_stat, flag: c_int) c_int; + /// int getchar(void); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/getchar.html pub extern fn getchar() c_int; @@ -1643,3 +1647,11 @@ pub fn pthread_self() pthread_t { pub fn gettid() pid_t { return libc.gettid(); } + +pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat { + var buf: struct_stat = undefined; + const rc = libc.fstatat(fd, path, &buf, flag); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); + return buf; +} -- 2.54.0