[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] Pascal-RTL: Short Writes berücksichtigen



! Pascal-RTL: Do_Write muss die übergebenen Daten komplett schreiben,
  fwrite kann allerdings Short Writes zurückgeben.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/pas/lib/rtl/sysfile.inc |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/modules/pas/lib/rtl/sysfile.inc b/src/modules/pas/lib/rtl/sysfile.inc
index 5143ef8..bcd0889 100644
--- a/src/modules/pas/lib/rtl/sysfile.inc
+++ b/src/modules/pas/lib/rtl/sysfile.inc
@@ -6,8 +6,8 @@ const
 function c_fopen(filename, mode: PChar): THandle; cdecl; external name 'fopen';
 function c_fclose(f: THandle): integer; cdecl; external name 'fclose';
 
-function c_fwrite(src: Pointer; blocksize, blockcount: TSize; f: THandle): TSize; cdecl; external name 'fwrite';
-function c_fread(dest: Pointer; blocksize, blockcount: TSize; f: THandle): TSize; cdecl; external name 'fread';
+function c_fwrite(src: Pointer; blocksize, blockcount: TSize; f: THandle): longint; cdecl; external name 'fwrite';
+function c_fread(dest: Pointer; blocksize, blockcount: TSize; f: THandle): longint; cdecl; external name 'fread';
 function c_fseek(f: THandle; offset, whence: longint): longint; cdecl; external name 'fseek';
 function c_ftell(f: THandle): TSize; cdecl; external name 'ftell';
 
@@ -36,8 +36,21 @@ begin { TODO } end;
 
 
 Function Do_Write(f: THandle; src: Pointer; len: TSize): TSize;
-begin 
-    Do_Write := c_fwrite(src, 1, len, f);
+var
+    ret: longint;
+begin
+    Do_Write := 0;
+    while len > 0 do begin
+        ret := c_fwrite(src, 1, len, f);
+        if ret < 0 then begin
+            InOutRes := 101;
+            exit(0);
+        end;
+
+        Inc(Do_Write, ret);
+        Inc(src, ret);
+        Dec(len, ret);
+    end;
 end;
 
 Function Do_Read(f: THandle; dest: Pointer; len: TSize): TSize;
-- 
1.6.0.2