Skip to content

Commit 52a451d

Browse files
kennethmyhrabgianfo
authored andcommitted
LibCore: Add syscall wrapper for chown()
1 parent 59d2999 commit 52a451d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Userland/Libraries/LibCore/System.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,21 @@ ErrorOr<void> chmod(StringView pathname, mode_t mode)
307307
#endif
308308
}
309309

310+
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
311+
{
312+
if (!pathname.characters_without_null_termination())
313+
return Error::from_syscall("chown"sv, -EFAULT);
314+
315+
#ifdef __serenity__
316+
Syscall::SC_chown_params params = { { pathname.characters_without_null_termination(), pathname.length() }, uid, gid };
317+
int rc = syscall(SC_chown, &params);
318+
HANDLE_SYSCALL_RETURN_VALUE("chown"sv, rc, {});
319+
#else
320+
String path = pathname;
321+
if (::chown(path.characters(), uid, gid) < 0)
322+
return Error::from_syscall("chown"sv, -errno);
323+
return {};
324+
#endif
325+
}
326+
310327
}

Userland/Libraries/LibCore/System.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
3+
* Copyright (c) 2021, Kenneth Myhra <kennethmyhra@gmail.com>
34
*
45
* SPDX-License-Identifier: BSD-2-Clause
56
*/
@@ -43,5 +44,6 @@ ErrorOr<void> ioctl(int fd, unsigned request, ...);
4344
ErrorOr<struct termios> tcgetattr(int fd);
4445
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
4546
ErrorOr<void> chmod(StringView pathname, mode_t mode);
47+
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
4648

4749
}

0 commit comments

Comments
 (0)