mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +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
2 changed files with 9 additions and 0 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue