implemented some functions h2-io-file.

renamed h2-sysapi to h2-os
This commit is contained in:
2014-06-05 15:26:37 +00:00
parent 744915575f
commit d78d6ffa1d
10 changed files with 339 additions and 78 deletions

View File

@ -2,7 +2,7 @@
with H2.Pool;
with H2.Sysdef;
separate (H2.Sysapi)
separate (H2.OS)
package body File is
@ -131,32 +131,35 @@ package body File is
end if;
end Close;
procedure Read (File: in File_Pointer; Buffer: in out System_Byte_Array; Last: out System_Length) is
procedure Read (File: in File_Pointer;
Buffer: in out System_Byte_Array;
Length: out System_Length) is
pragma Assert (Buffer'Length > 0);
F: Posix_File_Pointer := Posix_File_Pointer(File);
N: Sysdef.ssize_t;
begin
N := Sys_Read (F.Handle, Buffer'Address, Buffer'Length);
if Sysdef."<=" (N, ERROR_RETURN) then
raise Constraint_Error; -- TODO rename exception
elsif Sysdef."=" (N, 0) then
Last := Buffer'First - 1;
else
Last := Buffer'First + System_Length(N) - 1;
Length := System_Length(N);
end if;
end Read;
procedure Write (File: in File_Pointer; Buffer: in System_Byte_Array; Last: out System_Length) is
procedure Write (File: in File_Pointer;
Buffer: in System_Byte_Array;
Length: out System_Length) is
pragma Assert (Buffer'Length > 0);
F: Posix_File_Pointer := Posix_File_Pointer(File);
N: Sysdef.ssize_t;
begin
N := Sys_Write (F.Handle, Buffer'Address, Buffer'Length);
if Sysdef."<=" (N, ERROR_RETURN) then
raise Constraint_Error; -- TODO rename exception
elsif Sysdef."=" (N, 0) then
Last := Buffer'First - 1;
else
Last := Buffer'First + System_Length(N) - 1;
Length := System_Length(N);
end if;
end Write;
end File;