diff options
author | Lenny Maiorani <lenny@serenityos.org> | 2022-02-12 18:35:38 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-28 13:57:26 +0100 |
commit | b455363ce7e2a14f52624e236cbe8cb6288fd306 (patch) | |
tree | 450dd24e9856452b8ab838c5b5bc548660d44b4b | |
parent | 1dd70a6f490da6222478d4f0ba5f069a26a13104 (diff) | |
download | serenity-b455363ce7e2a14f52624e236cbe8cb6288fd306.zip |
LibCore: Add rmdir system call wrapper
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.h | 2 |
2 files changed, 16 insertions, 1 deletions
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<void> chdir(StringView path) #endif } +ErrorOr<void> 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<pid_t> 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<bool> isatty(int fd); ErrorOr<void> symlink(StringView target, StringView link_path); ErrorOr<void> mkdir(StringView path, mode_t); ErrorOr<void> chdir(StringView path); +ErrorOr<void> rmdir(StringView path); ErrorOr<pid_t> fork(); ErrorOr<int> mkstemp(Span<char> pattern); ErrorOr<void> fchmod(int fd, mode_t mode); @@ -142,5 +143,4 @@ ErrorOr<void> socketpair(int domain, int type, int protocol, int sv[2]); ErrorOr<Vector<gid_t>> getgroups(); ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev); ErrorOr<void> mkfifo(StringView pathname, mode_t mode); - } |