diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-10-01 11:15:02 +0000 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-11 19:55:37 -0700 |
commit | 9850a69cd199d48bc30a34e2fe38d5590b536aac (patch) | |
tree | 506a12437ac1651c9e25b2e08cdbc63ac80bf119 /Userland | |
parent | 5c1d5ed51da2cf3b9463413f704ea0e740950736 (diff) | |
download | serenity-9850a69cd199d48bc30a34e2fe38d5590b536aac.zip |
Kernel+LibC+LibCore: Implement `symlinkat(2)`
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibC/unistd.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibC/unistd.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 1 |
3 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index e3fbca0e9f..8e732f197a 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -673,11 +673,17 @@ int unlinkat(int dirfd, char const* pathname, int flags) // https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html int symlink(char const* target, char const* linkpath) { + return symlinkat(target, AT_FDCWD, linkpath); +} + +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlinkat.html +int symlinkat(char const* target, int newdirfd, char const* linkpath) +{ if (!target || !linkpath) { errno = EFAULT; return -1; } - Syscall::SC_symlink_params params { { target, strlen(target) }, { linkpath, strlen(linkpath) } }; + Syscall::SC_symlink_params params { { target, strlen(target) }, { linkpath, strlen(linkpath) }, newdirfd }; int rc = syscall(SC_symlink, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } diff --git a/Userland/Libraries/LibC/unistd.h b/Userland/Libraries/LibC/unistd.h index ee4bf2f1ae..ef8c28ad47 100644 --- a/Userland/Libraries/LibC/unistd.h +++ b/Userland/Libraries/LibC/unistd.h @@ -95,6 +95,7 @@ int link(char const* oldpath, char const* newpath); int unlink(char const* pathname); int unlinkat(int dirfd, char const* pathname, int flags); int symlink(char const* target, char const* linkpath); +int symlinkat(char const* target, int newdirfd, char const* linkpath); int rmdir(char const* pathname); int dup(int old_fd); int dup2(int old_fd, int new_fd); diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 2970c23dfe..f58b4952b7 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -839,6 +839,7 @@ ErrorOr<void> symlink(StringView target, StringView link_path) Syscall::SC_symlink_params params { .target = { target.characters_without_null_termination(), target.length() }, .linkpath = { link_path.characters_without_null_termination(), link_path.length() }, + .dirfd = AT_FDCWD, }; int rc = syscall(SC_symlink, ¶ms); HANDLE_SYSCALL_RETURN_VALUE("symlink", rc, {}); |