mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibCore: Add File::size()
Returns the size in bytes for a file path given its filename. Useful when file size is needed without having to open the file to query it using fstat() or seeking to the end.
This commit is contained in:
parent
368e74fdf8
commit
73924f9416
Notes:
sideshowbarker
2024-07-18 01:52:53 +09:00
Author: https://github.com/lpereira Commit: https://github.com/SerenityOS/serenity/commit/73924f94164 Pull-request: https://github.com/SerenityOS/serenity/pull/10278 Reviewed-by: https://github.com/kleinesfilmroellchen ✅
|
@ -153,6 +153,14 @@ bool File::exists(String const& filename)
|
|||
return stat(filename.characters(), &st) == 0;
|
||||
}
|
||||
|
||||
Result<size_t, OSError> File::size(String const& filename)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename.characters(), &st) < 0)
|
||||
return OSError(errno);
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
String File::real_path_for(String const& filename)
|
||||
{
|
||||
if (filename.is_null())
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
static bool is_link(String const& filename);
|
||||
|
||||
static bool exists(String const& filename);
|
||||
static Result<size_t, OSError> size(String const& filename);
|
||||
static bool ensure_parent_directories(String const& path);
|
||||
static String current_working_directory();
|
||||
static String absolute_path(String const& path);
|
||||
|
|
Loading…
Reference in a new issue