diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2021-11-27 15:23:16 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-11 15:10:42 -0800 |
commit | 52a451dcff3207df693b3571d48a0d875a5d241d (patch) | |
tree | d3c4be8d2a57ba6b15d037d0ee58e593da97c403 /Userland/Libraries/LibCore/System.cpp | |
parent | 59d299955eae8287fa4a43b37d83231390dbb179 (diff) | |
download | serenity-52a451dcff3207df693b3571d48a0d875a5d241d.zip |
LibCore: Add syscall wrapper for chown()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
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<void> chmod(StringView pathname, mode_t mode) #endif } +ErrorOr<void> 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 +} + } |