From b455363ce7e2a14f52624e236cbe8cb6288fd306 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Sat, 12 Feb 2022 18:35:38 -0700 Subject: [PATCH] LibCore: Add rmdir system call wrapper --- Userland/Libraries/LibCore/System.cpp | 15 +++++++++++++++ Userland/Libraries/LibCore/System.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index e19b111b54..bcac0946b4 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -766,6 +766,21 @@ ErrorOr chdir(StringView path) #endif } +ErrorOr rmdir(StringView path) +{ + if (path.is_null()) + return Error::from_errno(EFAULT); +#ifdef __serenity__ + int rc = syscall(SC_rmdir, path.characters_without_null_termination(), path.length()); + HANDLE_SYSCALL_RETURN_VALUE("rmdir"sv, rc, {}); +#else + String path_string = path; + if (::rmdir(path_string.characters()) < 0) + return Error::from_syscall("rmdir"sv, -errno); + return {}; +#endif +} + ErrorOr fork() { pid_t pid = ::fork(); diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index cf581ec08e..9dcc50877c 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -111,6 +111,7 @@ ErrorOr isatty(int fd); ErrorOr symlink(StringView target, StringView link_path); ErrorOr mkdir(StringView path, mode_t); ErrorOr chdir(StringView path); +ErrorOr rmdir(StringView path); ErrorOr fork(); ErrorOr mkstemp(Span pattern); ErrorOr fchmod(int fd, mode_t mode); @@ -142,5 +143,4 @@ ErrorOr socketpair(int domain, int type, int protocol, int sv[2]); ErrorOr> getgroups(); ErrorOr mknod(StringView pathname, mode_t mode, dev_t dev); ErrorOr mkfifo(StringView pathname, mode_t mode); - }