summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/stdio.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-10-01 11:42:25 +0000
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-11 19:55:37 -0700
commitd5fbdf1866981e251f36b8a40eb1c21cfa8912cd (patch)
tree1ead789a6b55ee634e0345daf428a295aaab6086 /Userland/Libraries/LibC/stdio.cpp
parenteb5389e933bec98735e71c3bab3706841647af48 (diff)
downloadserenity-d5fbdf1866981e251f36b8a40eb1c21cfa8912cd.zip
Kernel+LibC+LibCore: Implement `renameat(2)`
Now with the ability to specify different bases for the old and new paths.
Diffstat (limited to 'Userland/Libraries/LibC/stdio.cpp')
-rw-r--r--Userland/Libraries/LibC/stdio.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/stdio.cpp b/Userland/Libraries/LibC/stdio.cpp
index e73c64c856..ed34dd8101 100644
--- a/Userland/Libraries/LibC/stdio.cpp
+++ b/Userland/Libraries/LibC/stdio.cpp
@@ -1126,11 +1126,17 @@ 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);
}