From 4e4b7c272c88b32f127bbb0970e659ac5d04754f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 5 Sep 2021 17:55:43 +0200 Subject: [PATCH] Kernel: Use TRY() in sys$readlink() --- Kernel/Syscalls/readlink.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Kernel/Syscalls/readlink.cpp b/Kernel/Syscalls/readlink.cpp index 0a9c246041d..21b4a570fdc 100644 --- a/Kernel/Syscalls/readlink.cpp +++ b/Kernel/Syscalls/readlink.cpp @@ -16,27 +16,17 @@ KResultOr Process::sys$readlink(Userspaceview(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory()); - if (result.is_error()) - return result.error(); - auto description = result.value(); + auto path = TRY(get_syscall_path_argument(params.path)); + auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory())); if (!description->metadata().is_symlink()) return EINVAL; - auto contents = description->read_entire_file(); - if (contents.is_error()) - return contents.error(); - - auto& link_target = *contents.value(); - auto size_to_copy = min(link_target.size(), params.buffer.size); - TRY(copy_to_user(params.buffer.data, link_target.data(), size_to_copy)); + auto link_target = TRY(description->read_entire_file()); + auto size_to_copy = min(link_target->size(), params.buffer.size); + TRY(copy_to_user(params.buffer.data, link_target->data(), size_to_copy)); // Note: we return the whole size here, not the copied size. - return link_target.size(); + return link_target->size(); } }