mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 09:19:23 +02:00
* FileOpen should not open directories (Windows compatible) Bug ID #30766
git-svn-id: trunk@35063 -
This commit is contained in:
parent
0d772ae198
commit
d05175a17f
@ -443,9 +443,15 @@ end;
|
|||||||
|
|
||||||
Function FileOpenNoLocking (Const FileName : RawbyteString; Mode : Integer) : Longint;
|
Function FileOpenNoLocking (Const FileName : RawbyteString; Mode : Integer) : Longint;
|
||||||
|
|
||||||
|
Function IsHandleDirectory(Handle : Longint) : boolean;
|
||||||
|
Var Info : Stat;
|
||||||
|
begin
|
||||||
|
Result := (fpFStat(Handle, Info)<0) or fpS_ISDIR(info.st_mode);
|
||||||
|
end;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
SystemFileName: RawByteString;
|
SystemFileName: RawByteString;
|
||||||
LinuxFlags : longint;
|
fd,LinuxFlags : longint;
|
||||||
begin
|
begin
|
||||||
LinuxFlags:=0;
|
LinuxFlags:=0;
|
||||||
case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
|
case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
|
||||||
@ -456,8 +462,18 @@ begin
|
|||||||
|
|
||||||
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
|
||||||
repeat
|
repeat
|
||||||
FileOpenNoLocking:=fpOpen (pointer(SystemFileName),LinuxFlags);
|
fd:=fpOpen (pointer(SystemFileName),LinuxFlags);
|
||||||
until (FileOpenNoLocking<>-1) or (fpgeterrno<>ESysEINTR);
|
until (fd<>-1) or (fpgeterrno<>ESysEINTR);
|
||||||
|
|
||||||
|
{ Do not allow to open directories with FileOpen.
|
||||||
|
This would cause weird behavior of TFileStream.Size,
|
||||||
|
TMemoryStream.LoadFromFile etc. }
|
||||||
|
if (fd<>-1) and IsHandleDirectory(fd) then
|
||||||
|
begin
|
||||||
|
fpClose(fd);
|
||||||
|
fd:=feInvalidHandle;
|
||||||
|
end;
|
||||||
|
FileOpenNoLocking:=fd;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user