]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tools/nolibc: add support for access() and faccessat()
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Mon, 28 Apr 2025 12:40:08 +0000 (14:40 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Wed, 21 May 2025 13:32:06 +0000 (15:32 +0200)
This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-7-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/unistd.h
tools/testing/selftests/nolibc/nolibc-test.c

index ed253305fdbafd040ca5820207d8c53c6ea9f9fc..25bfc7732ec7e72a60f445588a233f72c008f7ef 100644 (file)
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 
+#define F_OK 0
+#define X_OK 1
+#define W_OK 2
+#define R_OK 4
+
+/*
+ * int access(const char *path, int amode);
+ * int faccessat(int fd, const char *path, int amode, int flag);
+ */
+
+static __attribute__((unused))
+int sys_faccessat(int fd, const char *path, int amode, int flag)
+{
+       return my_syscall4(__NR_faccessat, fd, path, amode, flag);
+}
+
+static __attribute__((unused))
+int faccessat(int fd, const char *path, int amode, int flag)
+{
+       return __sysret(sys_faccessat(fd, path, amode, flag));
+}
+
+static __attribute__((unused))
+int access(const char *path, int amode)
+{
+       return faccessat(AT_FDCWD, path, amode, 0);
+}
+
 
 static __attribute__((unused))
 int msleep(unsigned int msecs)
index 14a27bc6c83e4fda595b10dc29cf56b63904272a..10db118b8b111ec17f713d57240f193c7b18c70f 100644 (file)
@@ -1112,6 +1112,8 @@ int run_syscall(int min, int max)
                 * test numbers.
                 */
                switch (test + __LINE__ + 1) {
+               CASE_TEST(access);            EXPECT_SYSZR(proc, access("/proc/self", R_OK)); break;
+               CASE_TEST(access_bad);        EXPECT_SYSER(proc, access("/proc/self", W_OK), -1, EPERM); break;
                CASE_TEST(getpid);            EXPECT_SYSNE(1, getpid(), -1); break;
                CASE_TEST(getppid);           EXPECT_SYSNE(1, getppid(), -1); break;
                CASE_TEST(gettid);            EXPECT_SYSNE(has_gettid, gettid(), -1); break;