Kaynağa Gözat

Merged revisions 6713,6723-6724,6727,6732,6739,6746 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r6713 | jonas | 2007-03-04 19:46:50 +0100 (Sun, 04 Mar 2007) | 3 lines

* tv_sec field of timeval is time_t (just for form, the actual type
is the same as clong which was the previous type)

........
r6723 | hajny | 2007-03-05 01:17:27 +0100 (Mon, 05 Mar 2007) | 1 line

+ dynamically loaded 64-bit FS calls made available outside unit System
........
r6724 | hajny | 2007-03-05 01:29:11 +0100 (Mon, 05 Mar 2007) | 1 line

+ support for 64-bit FS calls
........
r6727 | hajny | 2007-03-06 00:47:10 +0100 (Tue, 06 Mar 2007) | 1 line

+ FileTruncate allows 64-bit parameter
........
r6732 | peter | 2007-03-06 08:13:20 +0100 (Tue, 06 Mar 2007) | 2 lines

* fixed compile error

........
r6739 | jonas | 2007-03-06 11:17:03 +0100 (Tue, 06 Mar 2007) | 2 lines

* enabled 64 bit filetruncate

........
r6746 | hajny | 2007-03-06 21:33:28 +0100 (Tue, 06 Mar 2007) | 1 line

* check for 64-bit support in FileTruncate based on TOff definition
........

git-svn-id: branches/fixes_2_2@8440 -

peter 18 yıl önce
ebeveyn
işleme
bdcb2b0279

+ 3 - 1
rtl/amiga/sysutils.pp

@@ -206,11 +206,13 @@ begin
 end;
 
 
-function FileTruncate(Handle, Size: LongInt): Boolean;
+function FileTruncate(Handle: longint; Size: Int64): Boolean;
 var
   dosResult: LongInt;
 begin
   FileTruncate:=False;
+  if Size > high (longint) then exit;
+{$WARNING Possible support for 64-bit FS to be checked!}
   if (Handle<=0) then exit;
 
   dosResult:=SetFileSize(Handle, Size, OFFSET_BEGINNING);

+ 1 - 1
rtl/beos/sysutils.pp

@@ -81,7 +81,7 @@ begin
 end;
 
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
+Function FileTruncate (Handle: longint;Size: Int64) : boolean;
 begin
 end;
 

+ 6 - 2
rtl/emx/sysutils.pp

@@ -513,15 +513,19 @@ begin
 end;
 
 
-function FileTruncate (Handle, Size: longint): boolean; assembler;
+function FileTruncate (Handle: THandle; Size: Int64): boolean; assembler;
 asm
  push ebx
 {$IFDEF REGCALL}
  mov ebx, eax
 {$ELSE REGCALL}
  mov ebx, Handle
- mov edx, Size
 {$ENDIF REGCALL}
+ mov edx, dword ptr Size
+ mov eax, dword ptr Size+4
+ or eax, eax
+ mov eax, 0
+ jz @FTruncEnd  (* file sizes > 4 GB not supported with EMX *)
  mov eax, 7F25h
  push ebx
  call syscall

+ 1 - 1
rtl/gba/sysutils.pp

@@ -102,7 +102,7 @@ begin
 end;
 
 
-function FileTruncate(Handle, Size: LongInt): Boolean;
+function FileTruncate(Handle: THandle; Size: Int64): Boolean;
 begin
   result := false;
 end;

+ 14 - 9
rtl/go32v2/sysutils.pp

@@ -240,18 +240,23 @@ begin
 end;
 
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
+Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
 var
   regs : trealregs;
 begin
-  FileSeek(Handle,Size,0);
-  Regs.realecx := 0;
-  Regs.realedx := tb_offset;
-  Regs.ds := tb_segment;
-  Regs.ebx := Handle;
-  Regs.eax:=$4000;
-  RealIntr($21, Regs);
-  FileTruncate:=(regs.realflags and carryflag)=0;
+  if Size > high (longint) then
+   FileTruncate := false
+  else
+   begin
+    FileSeek(Handle,Size,0);
+    Regs.realecx := 0;
+    Regs.realedx := tb_offset;
+    Regs.ds := tb_segment;
+    Regs.ebx := Handle;
+    Regs.eax:=$4000;
+    RealIntr($21, Regs);
+    FileTruncate:=(regs.realflags and carryflag)=0;
+   end;
 end;
 
 

+ 1 - 1
rtl/linux/ptypes.inc

@@ -125,7 +125,7 @@ Type
     pSockLen = ^socklen_t;
 
   timeval     = packed record
-                 tv_sec,
+                 tv_sec:time_t;
                  tv_usec:clong;
                 end;
   ptimeval    = ^timeval;

+ 1 - 1
rtl/macos/sysutils.pp

@@ -154,7 +154,7 @@ begin
   *)
 end;
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
+Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
 
 begin
   (* TODO fix

+ 5 - 1
rtl/morphos/sysutils.pp

@@ -206,11 +206,15 @@ begin
 end;
 
 
-function FileTruncate(Handle, Size: LongInt): Boolean;
+function FileTruncate(Handle: THandle; Size: Int64): Boolean;
 var
   dosResult: LongInt;
 begin
   FileTruncate:=False;
+  
+  if Size > high (longint) then exit;
+{$WARNING Possible support for 64-bit FS to be checked!}
+
   if (Handle<=0) then exit;
 
   dosResult:=SetFileSize(Handle, Size, OFFSET_BEGINNING);

+ 1 - 1
rtl/nds/sysutils.pp

@@ -102,7 +102,7 @@ begin
 end;
 
 
-function FileTruncate(Handle, Size: LongInt): Boolean;
+function FileTruncate(Handle: THandle; Size: Int64): Boolean;
 begin
   result := false;
 end;

+ 6 - 2
rtl/netware/sysutils.pp

@@ -146,10 +146,14 @@ begin
   _close(Handle);
 end;
 
-Function FileTruncate (Handle : THandle; Size: Longint) : boolean;
+Function FileTruncate (Handle : THandle; Size: Int64) : boolean;
 
 begin
-  FileTruncate:=(_chsize(Handle,Size) = 0);
+  if Size > high (longint) then
+   FileTruncate := false
+{$WARNING Possible support for 64-bit FS to be checked!}
+  else
+   FileTruncate:=(_chsize(Handle,Size) = 0);
 end;
 
 Function FileLock (Handle,FOffset,FLen : Longint) : Longint;

+ 6 - 2
rtl/netwlibc/sysutils.pp

@@ -143,9 +143,13 @@ begin
   libc.fpclose(Handle);
 end;
 
-Function FileTruncate (Handle : THandle; Size: Longint) : boolean;
+Function FileTruncate (Handle : THandle; Size: Int64) : boolean;
 begin
-  FileTruncate:=(libc.fpchsize(Handle,Size) = 0);
+  if Size > high (longint) then
+   FileTruncate := false
+{$WARNING Possible support for 64-bit FS to be checked!}
+  else
+   FileTruncate:=(libc.fpchsize(Handle,Size) = 0);
 end;
 
 Function FileLock (Handle : THandle; FOffset,FLen : Longint) : Longint;

+ 1 - 1
rtl/objpas/sysutils/filutilh.inc

@@ -79,7 +79,7 @@ Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
 Function FileSeek (Handle : THandle; FOffset, Origin: Longint) : Longint;
 Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
 Procedure FileClose (Handle : THandle);
-Function FileTruncate (Handle : THandle;Size: Longint) : boolean;
+Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
 Function FileAge (Const FileName : String): Longint;
 Function FileExists (Const FileName : String) : Boolean;
 Function DirectoryExists (Const Directory : String) : Boolean;

+ 6 - 6
rtl/os2/sysfile.inc

@@ -84,7 +84,7 @@ function Do_FilePos (Handle: THandle): int64;
 var
   PosActual: int64;
 begin
-  InOutRes := DosSetFilePtrL (Handle, 0, 1, PosActual);
+  InOutRes := Sys_DosSetFilePtrL (Handle, 0, 1, PosActual);
   Do_FilePos := PosActual;
 {$ifdef IODEBUG}
   writeln('do_filepos: handle=', Handle, ', actual_pos=', PosActual, ', InOutRes=', InOutRes);
@@ -95,7 +95,7 @@ procedure Do_Seek (Handle: THandle; Pos: int64);
 var
   PosActual: int64;
 begin
-  InOutRes:=DosSetFilePtrL(Handle, Pos, 0 {ZeroBased}, PosActual);
+  InOutRes:=Sys_DosSetFilePtrL(Handle, Pos, 0 {ZeroBased}, PosActual);
 {$ifdef IODEBUG}
   writeln('do_seek: handle=', Handle, ', pos=', pos, ', actual_pos=', PosActual, ', InOutRes=', InOutRes);
 {$endif}
@@ -105,7 +105,7 @@ function Do_SeekEnd (Handle: THandle): int64;
 var
   PosActual: int64;
 begin
-  InOutRes := DosSetFilePtrL (Handle, 0, 2 {EndBased}, PosActual);
+  InOutRes := Sys_DosSetFilePtrL (Handle, 0, 2 {EndBased}, PosActual);
   Do_SeekEnd := PosActual;
 {$ifdef IODEBUG}
   writeln('do_seekend: handle=', Handle, ', actual_pos=', PosActual, ', InOutRes=', InOutRes);
@@ -123,7 +123,7 @@ end;
 
 procedure Do_Truncate (Handle: THandle; Pos: int64);
 begin
-  InOutRes := DosSetFileSizeL (Handle, Pos);
+  InOutRes := Sys_DosSetFileSizeL (Handle, Pos);
   Do_SeekEnd (Handle);
 end;
 
@@ -221,12 +221,12 @@ begin
 
   Attrib:=32 {faArchive};
 
-  InOutRes:=DosOpenL(p, FileRec(F).Handle, Action, 0, Attrib, OpenFlags, FM, nil);
+  InOutRes:=Sys_DosOpenL(p, FileRec(F).Handle, Action, 0, Attrib, OpenFlags, FM, nil);
 
   // If too many open files try to set more file handles and open again
   if (InOutRes = 4) then
     if Increase_File_Handle_Count then
-      InOutRes:=DosOpenL(p, FileRec(F).Handle, Action, 0, Attrib, OpenFlags, FM, nil);
+      InOutRes:=Sys_DosOpenL(p, FileRec(F).Handle, Action, 0, Attrib, OpenFlags, FM, nil);
 
   If InOutRes<>0 then FileRec(F).Handle:=UnusedHandle;
 

+ 3 - 5
rtl/os2/sysos.inc

@@ -125,6 +125,8 @@ function DosGetDateTime(var Buf:TSysDateTime): cardinal; cdecl;
     external 'DOSCALLS' index 230;
 
 
+{
+Already declared in interface part:
 type
   TDosOpenL = function (FileName: PChar; var Handle: THandle;
                         var Action: cardinal; InitSize: int64;
@@ -135,7 +137,7 @@ type
                                         var PosActual: int64): cardinal; cdecl;
 
   TDosSetFileSizeL = function (Handle: THandle; Size: int64): cardinal; cdecl;
-
+}
 
 function DummyDosOpenL (FileName: PChar; var Handle: THandle;
                         var Action: cardinal; InitSize: int64;
@@ -164,10 +166,6 @@ end;
 
 
 const
-  DosOpenL: TDosOpenL = @DummyDosOpenL;
-  DosSetFilePtrL: TDosSetFilePtrL = @DummyDosSetFilePtrL;
-  DosSetFileSizeL: TDosSetFileSizeL = @DummyDosSetFileSizeL;
-
   OrdDosOpenL = 981;
   OrdDosSetFilePtrL = 988;
   OrdDosSetFileSizeL = 989;

+ 30 - 3
rtl/os2/system.pas

@@ -153,6 +153,33 @@ procedure SetDefaultOS2FileType (FType: ShortString);
 
 procedure SetDefaultOS2Creator (Creator: ShortString);
 
+type
+  TDosOpenL = function (FileName: PChar; var Handle: THandle;
+                        var Action: cardinal; InitSize: int64;
+                        Attrib, OpenFlags, FileMode: cardinal;
+                                                 EA: pointer): cardinal; cdecl;
+
+  TDosSetFilePtrL = function (Handle: THandle; Pos: int64; Method: cardinal;
+                                        var PosActual: int64): cardinal; cdecl;
+
+  TDosSetFileSizeL = function (Handle: THandle; Size: int64): cardinal; cdecl;
+
+
+function DummyDosOpenL (FileName: PChar; var Handle: THandle;
+                        var Action: cardinal; InitSize: int64;
+                        Attrib, OpenFlags, FileMode: cardinal;
+                                                 EA: pointer): cardinal; cdecl;
+
+function DummyDosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
+                                        var PosActual: int64): cardinal; cdecl;
+
+function DummyDosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
+
+
+const
+  Sys_DosOpenL: TDosOpenL = @DummyDosOpenL;
+  Sys_DosSetFilePtrL: TDosSetFilePtrL = @DummyDosSetFilePtrL;
+  Sys_DosSetFileSizeL: TDosSetFileSizeL = @DummyDosSetFileSizeL;
 
 
 implementation
@@ -750,15 +777,15 @@ begin
       begin
         if DosQueryProcAddr (DosCallsHandle, OrdDosOpenL, nil, P) = 0 then
           begin
-            DosOpenL := TDosOpenL (P);
+            Sys_DosOpenL := TDosOpenL (P);
             if DosQueryProcAddr (DosCallsHandle, OrdDosSetFilePtrL, nil, P) = 0
                                                                            then
               begin
-                DosSetFilePtrL := TDosSetFilePtrL (P);
+                Sys_DosSetFilePtrL := TDosSetFilePtrL (P);
                 if DosQueryProcAddr (DosCallsHandle, OrdDosSetFileSizeL, nil,
                                                                     P) = 0 then
                   begin
-                    DosSetFileSizeL := TDosSetFileSizeL (P);
+                    Sys_DosSetFileSizeL := TDosSetFileSizeL (P);
                     FSApi64 := true;
                   end;
               end;

+ 63 - 33
rtl/os2/sysutils.pp

@@ -102,13 +102,50 @@ type
             FileAlloc:cardinal;         {Amount of space the file really
                                          occupies on disk.}
             AttrFile:cardinal;          {Attributes of file.}
-            cbList:longint;             {Size of the file's extended attributes.}
+            cbList:cardinal;            {Size of the file's extended attributes.}
             Name:shortstring;           {Also possible to use as ASCIIZ.
                                          The byte following the last string
                                          character is always zero.}
         end;
         PFileFindBuf4=^TFileFindBuf4;
 
+        TFileFindBuf3L=object(TFileStatus)
+            NextEntryOffset: cardinal;  {Offset of next entry}
+            DateCreation,               {Date of file creation.}
+            TimeCreation,               {Time of file creation.}
+            DateLastAccess,             {Date of last access to file.}
+            TimeLastAccess,             {Time of last access to file.}
+            DateLastWrite,              {Date of last modification of file.}
+            TimeLastWrite:word;         {Time of last modification of file.}
+            FileSize,                   {Size of file.}
+            FileAlloc:int64;            {Amount of space the file really
+                                         occupies on disk.}
+            AttrFile:cardinal;          {Attributes of file.}
+            Name:shortstring;           {Also possible to use as ASCIIZ.
+                                         The byte following the last string
+                                         character is always zero.}
+        end;
+        PFileFindBuf3L=^TFileFindBuf3L;
+
+        TFileFindBuf4L=object(TFileStatus)
+            NextEntryOffset: cardinal;  {Offset of next entry}
+            DateCreation,               {Date of file creation.}
+            TimeCreation,               {Time of file creation.}
+            DateLastAccess,             {Date of last access to file.}
+            TimeLastAccess,             {Time of last access to file.}
+            DateLastWrite,              {Date of last modification of file.}
+            TimeLastWrite:word;         {Time of last modification of file.}
+            FileSize,                   {Size of file.}
+            FileAlloc:int64;            {Amount of space the file really
+                                         occupies on disk.}
+            AttrFile:cardinal;          {Attributes of file.}
+            cbList:cardinal;            {Size of the file's extended attributes.}
+            Name:shortstring;           {Also possible to use as ASCIIZ.
+                                         The byte following the last string
+                                         character is always zero.}
+        end;
+        PFileFindBuf4L=^TFileFindBuf4L;
+
  TFSInfo = record
             case word of
              1:
@@ -373,11 +410,6 @@ function DosSetPathInfo(FileName:PChar;InfoLevel:cardinal;
                         Options:cardinal):cardinal; cdecl;
     external 'DOSCALLS' index 219;
 
-function DosOpen(FileName:PChar;var Handle: THandle; var Action: cardinal;
-                 InitSize,Attrib,OpenFlags,FileMode:cardinal;
-                 EA:Pointer):cardinal; cdecl;
-    external 'DOSCALLS' index 273;
-
 function DosClose(Handle: THandle): cardinal; cdecl;
     external 'DOSCALLS' index 257;
 
@@ -389,13 +421,6 @@ function DosWrite(Handle: THandle; Buffer: pointer; Count: cardinal;
                                       var ActCount: cardinal): cardinal; cdecl;
     external 'DOSCALLS' index 282;
 
-function DosSetFilePtr(Handle: THandle; Pos: longint; Method: cardinal;
-                                     var PosActual: cardinal): cardinal; cdecl;
-    external 'DOSCALLS' index 256;
-
-function DosSetFileSize (Handle: THandle; Size: cardinal): cardinal; cdecl;
-    external 'DOSCALLS' index 272;
-
 procedure DosSleep (MSec: cardinal); cdecl; external 'DOSCALLS' index 229;
 
 function DosCreateQueue (var Handle: THandle; Priority:longint;
@@ -455,14 +480,14 @@ const
  FindResvdMask = $00003737; {Allowed bits in attribute
                              specification for DosFindFirst call.}
 
-function FileOpen (const FileName: string; Mode: integer): longint;
+function FileOpen (const FileName: string; Mode: integer): THandle;
 Var
   Handle: THandle;
   Rc, Action: cardinal;
 begin
 (* DenyNone if sharing not specified. *)
   if Mode and 112 = 0 then Mode:=Mode or 64;
-  Rc:=DosOpen(PChar (FileName), Handle, Action, 0, 0, 1, Mode, nil);
+  Rc:=Sys_DosOpenL(PChar (FileName), Handle, Action, 0, 0, 1, Mode, nil);
   If Rc=0 then
     FileOpen:=Handle
   else
@@ -470,27 +495,27 @@ begin
     //should return feInvalidHandle(=-1) if fail, other negative returned value are no more errors
 end;
 
-function FileCreate (const FileName: string): longint;
+function FileCreate (const FileName: string): THandle;
 Const
   Mode = ofReadWrite or faCreate or doDenyRW;   (* Sharing to DenyAll *)
 Var
   Handle: THandle;
   RC, Action: cardinal;
 Begin
-  RC:=DosOpen(PChar (FileName), Handle, Action, 0, 0, $12, Mode, Nil);
+  RC:=Sys_DosOpenL(PChar (FileName), Handle, Action, 0, 0, $12, Mode, Nil);
   If RC=0 then
     FileCreate:=Handle
   else
-    FileCreate:=-RC;
+    FileCreate:=feInvalidHandle;
 End;
 
-function FileCreate (const FileName: string; Mode: integer): longint;
+function FileCreate (const FileName: string; Mode: integer): THandle;
 begin
  FileCreate := FileCreate(FileName);
 end;
 
 
-function FileRead (Handle: longint; var Buffer; Count: longint): longint;
+function FileRead (Handle: THandle; var Buffer; Count: longint): longint;
 Var
   T: cardinal;
 begin
@@ -498,7 +523,7 @@ begin
   FileRead := longint (T);
 end;
 
-function FileWrite (Handle: longint; const Buffer; Count: longint): longint;
+function FileWrite (Handle: THandle; const Buffer; Count: longint): longint;
 Var
   T: cardinal;
 begin
@@ -506,30 +531,35 @@ begin
   FileWrite := longint (T);
 end;
 
-function FileSeek (Handle, FOffset, Origin: longint): longint;
+function FileSeek (Handle: THandle; FOffset, Origin: longint): longint;
 var
-  npos: cardinal;
+  NPos: int64;
 begin
-  if DosSetFilePtr (Handle, FOffset, Origin, npos) = 0 Then
-    FileSeek:= longint (npos)
+  if (Sys_DosSetFilePtrL (Handle, FOffset, Origin, NPos) = 0)
+                                               and (NPos < high (longint)) then
+    FileSeek:= longint (NPos)
   else
     FileSeek:=-1;
 end;
 
-function FileSeek (Handle: longint; FOffset: Int64; Origin: Longint): Int64;
+function FileSeek (Handle: THandle; FOffset: Int64; Origin: Longint): Int64;
+var
+  NPos: int64;
 begin
-  {$warning need to add 64bit call }
-  Result:=FileSeek(Handle,Longint(Foffset),Longint(Origin));
+  if Sys_DosSetFilePtrL (Handle, FOffset, Origin, NPos) = 0 then
+    FileSeek:= NPos
+  else
+    FileSeek:=-1;
 end;
 
-procedure FileClose (Handle: longint);
+procedure FileClose (Handle: THandle);
 begin
   DosClose(Handle);
 end;
 
-function FileTruncate (Handle, Size: longint): boolean;
+function FileTruncate (Handle: THandle; Size: Int64): boolean;
 begin
-  FileTruncate:=DosSetFileSize(Handle, Size)=0;
+  FileTruncate:=Sys_DosSetFileSizeL(Handle, Size)=0;
   FileSeek(Handle, 0, 2);
 end;
 
@@ -626,7 +656,7 @@ begin
   F.FindHandle := 0;
 end;
 
-function FileGetDate (Handle: longint): longint;
+function FileGetDate (Handle: THandle): longint;
 var
   FStat: TFileStatus3;
   Time: Longint;
@@ -642,7 +672,7 @@ begin
   FileGetDate:=Time;
 end;
 
-function FileSetDate (Handle, Age: longint): longint;
+function FileSetDate (Handle: THandle; Age: longint): longint;
 var
   FStat: PFileStatus3;
   RC: cardinal;

+ 6 - 2
rtl/unix/sysutils.pp

@@ -238,10 +238,14 @@ begin
   fpclose(Handle);
 end;
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
+Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
 
 begin
-  FileTruncate:=fpftruncate(Handle,Size)>=0;
+  if (SizeOf (TOff) < 8)   (* fpFTruncate only supporting signed 32-bit size *)
+                         and (Size > high (longint)) then
+    FileTruncate := false
+  else
+    FileTruncate:=fpftruncate(Handle,Size)>=0;
 end;
 
 Function UnixToWinAge(UnixAge : time_t): Longint;

+ 14 - 9
rtl/watcom/sysutils.pp

@@ -245,18 +245,23 @@ begin
 end;
 
 
-Function FileTruncate (Handle,Size: Longint) : boolean;
+Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
 var
   regs : trealregs;
 begin
-  FileSeek(Handle,Size,0);
-  Regs.realecx := 0;
-  Regs.realedx := tb_offset;
-  Regs.ds := tb_segment;
-  Regs.ebx := Handle;
-  Regs.eax:=$4000;
-  RealIntr($21, Regs);
-  FileTruncate:=(regs.realflags and carryflag)=0;
+  if Size > high (longint) then
+   FileTruncate := false
+  else
+   begin
+    FileSeek(Handle,Size,0);
+    Regs.realecx := 0;
+    Regs.realedx := tb_offset;
+    Regs.ds := tb_segment;
+    Regs.ebx := Handle;
+    Regs.eax:=$4000;
+    RealIntr($21, Regs);
+    FileTruncate:=(regs.realflags and carryflag)=0;
+   end;
 end;
 
 

+ 7 - 3
rtl/win/sysutils.pp

@@ -272,11 +272,15 @@ begin
 end;
 
 
-Function FileTruncate (Handle : THandle;Size: Longint) : boolean;
+Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
 begin
+{
   Result:=longint(SetFilePointer(handle,Size,nil,FILE_BEGIN))<>-1;
-  If Result then
-    Result:=SetEndOfFile(handle);
+}
+  if FileSeek (Handle, Size, FILE_BEGIN) = Size then
+   Result:=SetEndOfFile(handle)
+  else
+   Result := false;
 end;
 
 Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;

+ 5 - 4
rtl/wince/sysutils.pp

@@ -211,11 +211,12 @@ begin
 end;
 
 
-Function FileTruncate (Handle : THandle;Size: Longint) : boolean;
+Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
 begin
-  Result:=longint(SetFilePointer(handle,Size,nil,FILE_BEGIN))<>-1;
-  If Result then
-    Result:=SetEndOfFile(handle);
+  if FileSeek (Handle, Size, FILE_BEGIN) = Size then
+   Result:=SetEndOfFile(handle)
+  else
+   Result := false;
 end;