diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 15d8481886..bd6b00509a 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -307,4 +307,21 @@ ErrorOr chmod(StringView pathname, mode_t mode) #endif } +ErrorOr chown(StringView pathname, uid_t uid, gid_t gid) +{ + if (!pathname.characters_without_null_termination()) + return Error::from_syscall("chown"sv, -EFAULT); + +#ifdef __serenity__ + Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid }; + int rc = syscall(SC_chown, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("chown"sv, rc, {}); +#else + String path = pathname; + if (::chown(path.characters(), uid, gid) < 0) + return Error::from_syscall("chown"sv, -errno); + return {}; +#endif +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 801c1e5f61..dbf9d27026 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ @@ -43,5 +44,6 @@ 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); +ErrorOr chown(StringView pathname, uid_t uid, gid_t gid); }