mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-06 23:20:50 +01:00
* Reset filerec mode field to fmClosed if the system call to open the file failed
git-svn-id: trunk@29132 -
This commit is contained in:
parent
f456bb3a25
commit
7bbb30ccd4
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -400,6 +400,7 @@ begin
|
||||
GetInOutRes(lo(regs.realeax));
|
||||
if oldp<>p then
|
||||
freemem(p);
|
||||
FileRec(f).mode:=fmclosed;
|
||||
exit;
|
||||
end
|
||||
else
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -418,6 +418,7 @@ begin
|
||||
if res < 0 then begin
|
||||
errno := res;
|
||||
Errno2InoutRes;
|
||||
FileRec(f).mode:=fmclosed;
|
||||
end;
|
||||
if oldp<>p then
|
||||
freemem(p);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -327,7 +327,9 @@ begin
|
||||
FileRec(F).Mode := fmOutput;
|
||||
end;
|
||||
|
||||
end;
|
||||
end
|
||||
else
|
||||
FileRec(f).mode:=fmclosed;
|
||||
|
||||
if oldp<>p then
|
||||
freemem(p);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user