From a62d16fbe9704a4985dc819e4c63805cee85be3e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Nov 2021 11:36:00 +0100 Subject: [PATCH] LibCore: Use syscall wrappers in MappedFile::map_from_fd_and_close() --- Userland/Libraries/LibCore/MappedFile.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibCore/MappedFile.cpp b/Userland/Libraries/LibCore/MappedFile.cpp index fc98c43834..4851e35206 100644 --- a/Userland/Libraries/LibCore/MappedFile.cpp +++ b/Userland/Libraries/LibCore/MappedFile.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -26,18 +27,15 @@ ErrorOr> MappedFile::map(String const& path) ErrorOr> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] String const& path) { - if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) - return Error::from_errno(errno); + TRY(Core::System::fcntl(fd, F_SETFD, FD_CLOEXEC)); ScopeGuard fd_close_guard = [fd] { close(fd); }; - struct stat st; - if (fstat(fd, &st) < 0) - return Error::from_errno(errno); + auto stat = TRY(Core::System::fstat(fd)); + auto size = stat.st_size; - auto size = st.st_size; auto* ptr = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED)