Skip to content

SysUtils.FileSeek overload with Longint

Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;

begin
  result:=longint(FileSeek(Handle,int64(FOffset),Origin));
end;


Function FileSeek (Handle : Longint; FOffset : Int64; Origin : Longint) : Int64;
begin
  FileSeek:=fplSeek (Handle,FOffset,Origin);
end;

A man tells about a problem with 1st FileSeek variant: https://forum.lazarus.freepascal.org/index.php?topic=56588.msg422001#msg422001

I suggest to help him. 1st overload must not be used for file sizes>2G, because we will get negative result in longint() cast. Let's raise an exception here, if longint() gets too huge value, value>2G. This way, man will see an exception and will edit his code, to force usage of 2nd FileSeek overload. Which gives OK result for all file sizes.

Edited by Alexey Torgashin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information