diff mbox series

[v1,06/17] tools/nolibc: add rmdir() support

Message ID 12a992919bea416bbc073d869c90d03c5ad1c7ac.1687344643.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series selftests/nolibc: allow run with minimal kernel config | expand

Commit Message

Zhangjin Wu June 21, 2023, 1 p.m. UTC
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@tinylab.org>
---
 tools/include/nolibc/sys.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox series

Patch

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);