1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:27:43 +00:00

LibCore: Add syscall wrapper for chmod()

This commit is contained in:
Kenneth Myhra 2021-11-27 15:46:11 +01:00 committed by Brian Gianforcaro
parent 294cb3cef4
commit 0d76d15f9d
2 changed files with 17 additions and 0 deletions

View file

@ -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
}
}