diff --git a/rtl/emx/sysutils.pp b/rtl/emx/sysutils.pp index 251862821b..273dd3a106 100644 --- a/rtl/emx/sysutils.pp +++ b/rtl/emx/sysutils.pp @@ -410,6 +410,7 @@ asm mov eax, 7F2Bh call syscall pop ebx + //check me, should return feInvalidHandle(=-1) if fail, other negative returned value are no more errors end {['eax', 'ebx', 'ecx', 'edx']}; diff --git a/rtl/objpas/classes/streams.inc b/rtl/objpas/classes/streams.inc index bbc751e6fb..564ed5392e 100644 --- a/rtl/objpas/classes/streams.inc +++ b/rtl/objpas/classes/streams.inc @@ -419,7 +419,8 @@ begin FHandle:=FileCreate(AFileName) else FHAndle:=FileOpen(AFileName,Mode); - If FHandle<0 then + + If (FHandle=feInvalidHandle) then If Mode=fmcreate then raise EFCreateError.createfmt(SFCreateError,[AFileName]) else @@ -435,7 +436,8 @@ begin FHandle:=FileCreate(AFileName) else FHAndle:=FileOpen(AFileName,Mode); - If FHandle<0 then + + If (FHandle=feInvalidHandle) then If Mode=fmcreate then raise EFCreateError.createfmt(SFCreateError,[AFileName]) else diff --git a/rtl/objpas/sysutils/filutilh.inc b/rtl/objpas/sysutils/filutilh.inc index bba5d12c3c..e693f35f8e 100644 --- a/rtl/objpas/sysutils/filutilh.inc +++ b/rtl/objpas/sysutils/filutilh.inc @@ -68,6 +68,9 @@ Const fsFromCurrent = 1; fsFromEnd = 2; + { File errors } + feInvalidHandle : THandle = -1; //return value on FileOpen error + Function FileOpen (Const FileName : string; Mode : Integer) : THandle; Function FileCreate (Const FileName : String) : THandle; Function FileCreate (Const FileName : String; Mode : Integer) : THandle; diff --git a/rtl/objpas/sysutils/sysutils.inc b/rtl/objpas/sysutils/sysutils.inc index 38d67985bb..34be6332f8 100644 --- a/rtl/objpas/sysutils/sysutils.inc +++ b/rtl/objpas/sysutils/sysutils.inc @@ -65,7 +65,7 @@ begin fd:=FileOpen(FileName,fmOpenRead); - If (Fd>=0) then + If (Fd<>feInvalidHandle) then try Result:=FileSetDate(fd,Age); finally diff --git a/rtl/os2/sysutils.pp b/rtl/os2/sysutils.pp index 30f7bdd970..8bddc182a3 100644 --- a/rtl/os2/sysutils.pp +++ b/rtl/os2/sysutils.pp @@ -466,7 +466,8 @@ begin If Rc=0 then FileOpen:=Handle else - FileOpen:=-RC; + FileOpen:=feInvalidHandle; //FileOpen:=-RC; + //should return feInvalidHandle(=-1) if fail, other negative returned value are no more errors end; function FileCreate (const FileName: string): longint; diff --git a/rtl/win/sysutils.pp b/rtl/win/sysutils.pp index c143ce4697..278281eda7 100644 --- a/rtl/win/sysutils.pp +++ b/rtl/win/sysutils.pp @@ -158,6 +158,7 @@ begin result := CreateFile(@FN[1], dword(AccessMode[Mode and 3]), dword(ShareMode[(Mode and $F0) shr 4]), nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1) end; diff --git a/rtl/wince/sysutils.pp b/rtl/wince/sysutils.pp index 373e36965d..ad37301c23 100644 --- a/rtl/wince/sysutils.pp +++ b/rtl/wince/sysutils.pp @@ -147,6 +147,7 @@ begin result := CreateFile(fn, dword(AccessMode[Mode and 3]), dword(ShareMode[(Mode and $F0) shr 4]), nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1) FreeMem(fn); end;