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 tcsetattr(int fd, int optional_actions, struct termios const& ios) return {}; } +ErrorOr 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 +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 8bda871631..14b26db2e4 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -41,5 +41,6 @@ ErrorOr gethostname(); ErrorOr ioctl(int fd, unsigned request, ...); ErrorOr tcgetattr(int fd); ErrorOr tcsetattr(int fd, int optional_actions, struct termios const&); +ErrorOr chmod(StringView pathname, mode_t mode); }