mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 08:50:37 +00:00
Kernel+LibC+LibCore: Implement symlinkat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
This commit is contained in:
parent
5c1d5ed51d
commit
9850a69cd1
Notes:
sideshowbarker
2024-07-17 16:23:06 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/9850a69cd1 Pull-request: https://github.com/SerenityOS/serenity/pull/15428 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi
5 changed files with 11 additions and 2 deletions
|
@ -413,6 +413,7 @@ struct SC_mknod_params {
|
|||
struct SC_symlink_params {
|
||||
StringArgument target;
|
||||
StringArgument linkpath;
|
||||
int dirfd;
|
||||
};
|
||||
|
||||
struct SC_rename_params {
|
||||
|
|
|
@ -29,7 +29,7 @@ ErrorOr<FlatPtr> Process::sys$symlink(Userspace<Syscall::SC_symlink_params const
|
|||
|
||||
auto target = TRY(get_syscall_path_argument(params.target));
|
||||
auto linkpath = TRY(get_syscall_path_argument(params.linkpath));
|
||||
TRY(VirtualFileSystem::the().symlink(credentials(), target->view(), linkpath->view(), current_directory()));
|
||||
TRY(VirtualFileSystem::the().symlink(credentials(), target->view(), linkpath->view(), TRY(custody_for_dirfd(params.dirfd))));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -672,12 +672,18 @@ 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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, {});
|
||||
|
|
Loading…
Reference in a new issue