1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

Kernel+LibC+LibCore: Implement renameat(2)

Now with the ability to specify different bases for the old and new
paths.
This commit is contained in:
sin-ack 2022-10-01 11:42:25 +00:00 committed by Andrew Kaster
parent eb5389e933
commit d5fbdf1866
7 changed files with 17 additions and 6 deletions

View file

@ -1125,12 +1125,18 @@ int fclose(FILE* stream)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
int rename(char const* oldpath, char const* newpath)
{
return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/renameat.html
int renameat(int olddirfd, char const* oldpath, int newdirfd, char const* newpath)
{
if (!oldpath || !newpath) {
errno = EFAULT;
return -1;
}
Syscall::SC_rename_params params { { oldpath, strlen(oldpath) }, { newpath, strlen(newpath) } };
Syscall::SC_rename_params params { olddirfd, { oldpath, strlen(oldpath) }, newdirfd, { newpath, strlen(newpath) } };
int rc = syscall(SC_rename, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}