diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2021-11-27 15:46:11 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-04 15:05:46 -0800 |
commit | 0d76d15f9d17d7ca318a18eb69a0334a74d9d708 (patch) | |
tree | a8a13b5ca3b087288bac6cf08873fff6b26928c4 /Userland/Libraries/LibCore/System.cpp | |
parent | 294cb3cef483b1a99a47bc715bff3e4b27e0d409 (diff) | |
download | serenity-0d76d15f9d17d7ca318a18eb69a0334a74d9d708.zip |
LibCore: Add syscall wrapper for chmod()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index c22ec3de4d..01cf0a24a7 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -275,4 +275,20 @@ ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const& ios) return {}; } +ErrorOr<void> chmod(StringView pathname, mode_t mode) +{ + if (!pathname.characters_without_null_termination()) + return Error::from_syscall("chmod"sv, -EFAULT); + +#ifdef __serenity__ + int rc = syscall(SC_chmod, pathname.characters_without_null_termination(), pathname.length(), mode); + HANDLE_SYSCALL_RETURN_VALUE("chmod"sv, rc, {}); +#else + String path = pathname; + if (::chmod(path.characters(), mode) < 0) + return Error::from_syscall("chmod"sv, -errno); + return {}; +#endif +} + } |