mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibCore: Add syscall wrapper for rename()
This commit is contained in:
parent
fb4ffe22c8
commit
ead9c36c92
2 changed files with 22 additions and 0 deletions
|
@ -503,4 +503,25 @@ ErrorOr<int> mkstemp(Span<char> pattern)
|
|||
return fd;
|
||||
}
|
||||
|
||||
ErrorOr<void> rename(StringView old_path, StringView new_path)
|
||||
{
|
||||
if (old_path.is_null() || new_path.is_null())
|
||||
return Error::from_errno(EFAULT);
|
||||
|
||||
#ifdef __serenity__
|
||||
Syscall::SC_rename_params params {
|
||||
.old_path = { old_path.characters_without_null_termination(), old_path.length() },
|
||||
.new_path = { new_path.characters_without_null_termination(), new_path.length() },
|
||||
};
|
||||
int rc = syscall(SC_rename, ¶ms);
|
||||
HANDLE_SYSCALL_RETURN_VALUE("rename"sv, rc, {});
|
||||
#else
|
||||
String old_path_string = old_path;
|
||||
String new_path_string = new_path;
|
||||
if (::rename(old_path_string.characters(), new_path_string.characters()) < 0)
|
||||
return Error::from_syscall("rename"sv, -errno);
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue