mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-17 18:41:22 +00:00
posix file: Add procedure to query the size of a file
Change-Id: Ib3b31e90ca98dc09185463ce467a70770e0f222d Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/21095 Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
with Interfaces.C;
|
||||
with Interfaces.C.Strings;
|
||||
with Ada.Directories;
|
||||
|
||||
with HW.Debug;
|
||||
|
||||
@@ -68,4 +69,18 @@ package body HW.File is
|
||||
pragma Debug (not Success, Debug.New_Line);
|
||||
end Map;
|
||||
|
||||
procedure Size (Length : out Natural; Path : String)
|
||||
with
|
||||
SPARK_Mode => Off
|
||||
is
|
||||
use type Ada.Directories.File_Size;
|
||||
Res_Size : Ada.Directories.File_Size;
|
||||
begin
|
||||
Res_Size := Ada.Directories.Size (Path);
|
||||
Length := Natural (Res_Size);
|
||||
exception
|
||||
when others =>
|
||||
Length := 0;
|
||||
end Size;
|
||||
|
||||
end HW.File;
|
||||
|
||||
@@ -39,4 +39,8 @@ package HW.File is
|
||||
Pre => (Readable or Writable) and
|
||||
(if Map_Copy then Readable and not Writable);
|
||||
|
||||
-- Sets `Length` to the size of the file given by `Path` or 0 if an
|
||||
-- error occurs.
|
||||
procedure Size (Length : out Natural; Path : String);
|
||||
|
||||
end HW.File;
|
||||
|
||||
Reference in New Issue
Block a user