[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <12a992919bea416bbc073d869c90d03c5ad1c7ac.1687344643.git.falcon@tinylab.org>
Date: Wed, 21 Jun 2023 21:00:33 +0800
From: Zhangjin Wu <falcon@...ylab.org>
To: w@....eu
Cc: thomas@...ch.de, arnd@...db.de, falcon@...ylab.org,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: [PATCH v1 06/17] tools/nolibc: add rmdir() support
A reverse operation of mkdir is meaningful, add rmdir() here.
This is required by nolibc-test to remove /proc if CONFIG_PROC_FS not
enabled.
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
---
tools/include/nolibc/sys.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 856249a11890..8ddfd9185da6 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -716,6 +716,34 @@ int mkdir(const char *path, mode_t mode)
return ret;
}
+/*
+ * int rmdir(const char *path);
+ */
+
+static __attribute__((unused))
+int sys_rmdir(const char *path)
+{
+#ifdef __NR_rmdir
+ return my_syscall1(__NR_rmdir, path);
+#elif defined(__NR_unlinkat)
+ return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
+#else
+ return -ENOSYS;
+#endif
+}
+
+static __attribute__((unused))
+int rmdir(const char *path)
+{
+ int ret = sys_rmdir(path);
+
+ if (ret < 0) {
+ SET_ERRNO(-ret);
+ ret = -1;
+ }
+ return ret;
+}
+
/*
* int mknod(const char *path, mode_t mode, dev_t dev);
--
2.25.1
Powered by blists - more mailing lists