summaryrefslogtreecommitdiff
path: root/tools/include/nolibc/sys.h
diff options
context:
space:
mode:
authorLouis Taylor <louis@kragniz.eu>2025-03-06 18:41:18 +0000
committerThomas Weißschuh <linux@weissschuh.net>2025-03-06 22:30:20 +0100
commitb2edaad7f5192a79384b7d0bec62312b668da463 (patch)
tree597e19e474dde90b59d0506287d23a4aa3e39467 /tools/include/nolibc/sys.h
parentcb839e0cc881b4abd4a2e64cd06c2e313987a189 (diff)
tools/nolibc: add support for openat(2)
openat is useful to avoid needing to construct relative paths, so expose a wrapper for using it directly. Signed-off-by: Louis Taylor <louis@kragniz.eu> Link: https://lore.kernel.org/r/20250306184147.208723-1-louis@kragniz.eu Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to 'tools/include/nolibc/sys.h')
-rw-r--r--tools/include/nolibc/sys.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 8f44c33b1213..3cd938f9abda 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -765,6 +765,31 @@ int mount(const char *src, const char *tgt,
return __sysret(sys_mount(src, tgt, fst, flags, data));
}
+/*
+ * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
+ */
+
+static __attribute__((unused))
+int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
+{
+ return my_syscall4(__NR_openat, dirfd, path, flags, mode);
+}
+
+static __attribute__((unused))
+int openat(int dirfd, const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return __sysret(sys_openat(dirfd, path, flags, mode));
+}
/*
* int open(const char *path, int flags[, mode_t mode]);