diff --git a/rtl/amicommon/sysfile.inc b/rtl/amicommon/sysfile.inc index 5760377925..93260429fb 100644 --- a/rtl/amicommon/sysfile.inc +++ b/rtl/amicommon/sysfile.inc @@ -89,7 +89,7 @@ begin l^.next:=p; end {$IFDEF ASYS_FPC_FILEDEBUG} - else + else RawDoFmt('FPC_FILE_DEBUG: Error! Trying add filehandle a filehandle twice: $%lx !'+#10,@h,pointer(1),nil); {$ENDIF} ; @@ -112,14 +112,14 @@ begin while (p^.next<>nil) and (not inList) do if p^.next^.handle=h then inList:=True else p:=p^.next; - + if inList then begin tmpList:=p^.next^.next; dispose(p^.next); p^.next:=tmpList; end {$IFDEF ASYS_FPC_FILEDEBUG} - else + else RawDoFmt('FPC_FILE_DEBUG: Error! Trying to remove not existing filehandle: $%lx !'+#10,@h,pointer(1),nil); {$ENDIF} ; @@ -132,7 +132,7 @@ function CheckInList(var l: PFileList; h: LongInt): pointer; alias: 'CHECKINLIST var p : PFileList; inList : Pointer; - + begin inList:=nil; if l=nil then begin @@ -240,7 +240,7 @@ begin do_filepos:=-1; if CheckInList(ASYS_fileList,handle)<>nil then begin - { Seeking zero from OFFSET_CURRENT to find out where we are } + { Seeking zero from OFFSET_CURRENT to find out where we are } dosResult:=dosSeek(handle,0,OFFSET_CURRENT); if dosResult<0 then begin dosError2InOut(IoErr); @@ -255,7 +255,7 @@ begin checkCTRLC; if CheckInList(ASYS_fileList,handle)<>nil then begin - { Seeking from OFFSET_BEGINNING } + { Seeking from OFFSET_BEGINNING } if dosSeek(handle,pos,OFFSET_BEGINNING)<0 then dosError2InOut(IoErr); end; @@ -363,7 +363,10 @@ begin handle:=Open(@tmpStr,openflags); if handle=0 then begin - dosError2InOut(IoErr); + begin + dosError2InOut(IoErr); + FileRec(f).mode:=fmclosed; + end end else begin AddToList(ASYS_fileList,handle); filerec(f).handle:=handle; diff --git a/rtl/atari/sysfile.inc b/rtl/atari/sysfile.inc index ce874bbbfd..961bd35666 100644 --- a/rtl/atari/sysfile.inc +++ b/rtl/atari/sysfile.inc @@ -324,7 +324,10 @@ begin move.w d0,i { get handle as SIGNED VALUE... } end; if errno <> 0 then + begin Error2InOut; + FileRec(f).mode:=fmclosed; + end; filerec(f).handle:=i; if ((flags and $100) <> 0) and (FileRec (F).Handle <> UnusedHandle) then diff --git a/rtl/emx/sysfile.inc b/rtl/emx/sysfile.inc index ab1cd005dc..3f86765a80 100644 --- a/rtl/emx/sysfile.inc +++ b/rtl/emx/sysfile.inc @@ -368,7 +368,9 @@ begin do_seekend (FileRec (F).Handle); FileRec (F).Mode := fmOutput; {fool fmappend} end; - end; + end + else + FileRec(f).mode:=fmclosed; if oldp<>p then freemem(p); end; diff --git a/rtl/go32v2/sysfile.inc b/rtl/go32v2/sysfile.inc index fdbec9fa85..5721c7029f 100644 --- a/rtl/go32v2/sysfile.inc +++ b/rtl/go32v2/sysfile.inc @@ -400,6 +400,7 @@ begin GetInOutRes(lo(regs.realeax)); if oldp<>p then freemem(p); + FileRec(f).mode:=fmclosed; exit; end else diff --git a/rtl/macos/sysfile.inc b/rtl/macos/sysfile.inc index 8e6b7f438a..28359199e1 100644 --- a/rtl/macos/sysfile.inc +++ b/rtl/macos/sysfile.inc @@ -289,7 +289,10 @@ begin InOutRes:= MacOSErr2RTEerr(err); end; if InOutRes <> 0 then - exit; + begin + FileRec(f).mode:=fmclosed; + exit; + end; p:= PChar(fullPath); end; @@ -319,8 +322,10 @@ begin filerec(f).handle:= fh; end else - filerec(f).handle:= UnusedHandle; - + begin + filerec(f).handle:= UnusedHandle; + FileRec(f).mode:=fmclosed; + end; {$else} InOutRes:=1; @@ -343,6 +348,7 @@ begin if (filerec(f).handle=UnusedHandle) then begin + FileRec(f).mode:=fmclosed; //errno:=GetLastError; //Errno2InoutRes; end; diff --git a/rtl/msdos/sysfile.inc b/rtl/msdos/sysfile.inc index 4b78e71d43..7f7815f6a2 100644 --- a/rtl/msdos/sysfile.inc +++ b/rtl/msdos/sysfile.inc @@ -344,6 +344,7 @@ begin {$endif RTLLITE} if (regs.Flags and fCarry) <> 0 then begin + FileRec(f).mode:=fmclosed; GetInOutRes(regs.AX); if oldp<>p then freemem(p); @@ -381,6 +382,7 @@ begin do_seekend(filerec(f).handle); filerec(f).mode:=fmoutput; {fool fmappend} end; + if oldp<>p then freemem(p); end; diff --git a/rtl/nativent/sysfile.inc b/rtl/nativent/sysfile.inc index 7681f65003..caeb8dc888 100644 --- a/rtl/nativent/sysfile.inc +++ b/rtl/nativent/sysfile.inc @@ -418,6 +418,7 @@ begin if res < 0 then begin errno := res; Errno2InoutRes; + FileRec(f).mode:=fmclosed; end; if oldp<>p then freemem(p); diff --git a/rtl/nds/sysfile.inc b/rtl/nds/sysfile.inc index f265b5d293..2b79599227 100644 --- a/rtl/nds/sysfile.inc +++ b/rtl/nds/sysfile.inc @@ -97,7 +97,7 @@ begin if res <> 0 then SetFileError(res) else - InOutRes := 0; + InOutRes := 0; end; procedure do_rename(p1, p2: pchar; p1changeable, p2changeable: boolean); @@ -109,7 +109,7 @@ begin if res <> 0 then SetFileError(res) else - InOutRes := 0; + InOutRes := 0; end; function do_write(h: THandle; addr: pointer; len: longint) : longint; @@ -122,7 +122,7 @@ begin InOutRes := 0 else SetFileError(res); - do_write := res; + do_write := res; end; function do_read(h: THandle; addr: pointer; len: longint) : longint; @@ -143,14 +143,14 @@ var res: longint; begin InOutRes := 0; - + //result := ftell(P_FILE(handle)); res := _tell(handle); if res < 0 then SetFileError(res) else InOutRes := 0; - do_filepos := res; + do_filepos := res; end; procedure do_seek(handle: THandle; pos: longint); @@ -175,7 +175,7 @@ begin SetFileError(res) else InOutRes := 0; - do_seekend := res; + do_seekend := res; end; function do_filesize(handle: THandle): longint; @@ -206,7 +206,7 @@ begin if res <> 0 then SetFileError(res) else - InOutRes := 0; + InOutRes := 0; end; procedure do_open(var f;p:pchar;flags:longint; pchangeable: boolean); @@ -284,7 +284,10 @@ begin FileRec(f).Handle := _open(p,oflags,438); end; if (errno^ <> 0) or (longint(FileRec(f).Handle) < 0) then - Errno2Inoutres + begin + Errno2Inoutres; + FileRec(f).mode:=fmclosed; + end else InOutRes := 0; end; diff --git a/rtl/netware/sysfile.inc b/rtl/netware/sysfile.inc index 8c85d29c5b..ad7a723470 100644 --- a/rtl/netware/sysfile.inc +++ b/rtl/netware/sysfile.inc @@ -264,7 +264,10 @@ Begin FileRec(f).Handle := _open(p,oflags,438); end; IF FileRec(f).Handle < 0 THEN - Errno2Inoutres + begin + Errno2Inoutres; + FileRec(f).mode:=fmclosed; + end ELSE InOutRes := 0; End; diff --git a/rtl/netwlibc/sysfile.inc b/rtl/netwlibc/sysfile.inc index 9a5c94280b..2ca75b1390 100644 --- a/rtl/netwlibc/sysfile.inc +++ b/rtl/netwlibc/sysfile.inc @@ -296,7 +296,10 @@ Begin FileRec(f).Handle := open(p,oflags,438); end; if (___errno^ <> 0) or (longint(FileRec(f).Handle) < 0) then - Errno2Inoutres + begin + Errno2Inoutres; + FileRec(f).mode:=fmclosed; + end else InOutRes := 0; end; @@ -382,7 +385,10 @@ Begin FileRec(f).Handle := _open(p,oflags,438); end;} if FileRec(f).Handle = 0 then - Errno2Inoutres + begin + Errno2Inoutres; + FileRec(f).mode:=fmclosed; + end else InOutRes := 0; End; diff --git a/rtl/os2/sysfile.inc b/rtl/os2/sysfile.inc index f406ccb0b2..172223cd27 100644 --- a/rtl/os2/sysfile.inc +++ b/rtl/os2/sysfile.inc @@ -327,7 +327,9 @@ begin FileRec(F).Mode := fmOutput; end; - end; + end + else + FileRec(f).mode:=fmclosed; if oldp<>p then freemem(p); diff --git a/rtl/unix/sysfile.inc b/rtl/unix/sysfile.inc index f9f0c1583b..acc6d76315 100644 --- a/rtl/unix/sysfile.inc +++ b/rtl/unix/sysfile.inc @@ -228,7 +228,10 @@ Begin until (FileRec(f).Handle<>-1) or (geterrno<>ESysEINTR); end; If Filerec(f).Handle<0 Then - Errno2Inoutres + begin + Errno2Inoutres; + FileRec(f).mode:=fmclosed; + end else InOutRes:=0; End; diff --git a/rtl/watcom/sysfile.inc b/rtl/watcom/sysfile.inc index d962d751f1..3d7285b8ee 100644 --- a/rtl/watcom/sysfile.inc +++ b/rtl/watcom/sysfile.inc @@ -392,6 +392,7 @@ begin if (regs.realflags and carryflag) <> 0 then begin GetInOutRes(lo(regs.realeax)); + FileRec(f).mode:=fmclosed; if oldp<>p then freemem(p); exit; diff --git a/rtl/win/sysfile.inc b/rtl/win/sysfile.inc index 1882a4e985..e4a12eb0c0 100644 --- a/rtl/win/sysfile.inc +++ b/rtl/win/sysfile.inc @@ -313,6 +313,7 @@ begin if (filerec(f).handle=0) or (filerec(f).handle=UnusedHandle) then begin Errno2InoutRes(GetLastError); + FileRec(f).mode:=fmclosed; end; if oldp<>p then freemem(p);