From a70d79ff9821c2fc35e29f50062035dc3949e8a4 Mon Sep 17 00:00:00 2001 From: implicitfield <114500360+implicitfield@users.noreply.github.com> Date: Tue, 16 Jan 2024 14:08:05 +0400 Subject: [PATCH] LibFileSystem: Add a helper to get the file size from fstat --- Userland/Libraries/LibFileSystem/FileSystem.cpp | 6 ++++++ Userland/Libraries/LibFileSystem/FileSystem.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Userland/Libraries/LibFileSystem/FileSystem.cpp b/Userland/Libraries/LibFileSystem/FileSystem.cpp index a931eea9df..f6b5767da6 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.cpp +++ b/Userland/Libraries/LibFileSystem/FileSystem.cpp @@ -356,6 +356,12 @@ ErrorOr size_from_stat(StringView path) return st.st_size; } +ErrorOr size_from_fstat(int fd) +{ + auto st = TRY(Core::System::fstat(fd)); + return st.st_size; +} + bool can_delete_or_move(StringView path) { VERIFY(!path.is_empty()); diff --git a/Userland/Libraries/LibFileSystem/FileSystem.h b/Userland/Libraries/LibFileSystem/FileSystem.h index b520986ed2..400f07b09d 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.h +++ b/Userland/Libraries/LibFileSystem/FileSystem.h @@ -72,6 +72,7 @@ ErrorOr copy_file_or_directory(StringView destination_path, StringView sou ErrorOr move_file(StringView destination_path, StringView source_path, PreserveMode = PreserveMode::Nothing); ErrorOr remove(StringView path, RecursionMode); ErrorOr size_from_stat(StringView path); +ErrorOr size_from_fstat(int fd); bool can_delete_or_move(StringView path); ErrorOr read_link(StringView link_path);