* fixed linux flock type by defining and using a kernel_off_t type

whose size depends on whether the run time environment is 32 or
    64 bit (mantis #13647)
  + added flock64 type for 32 bit systems (usable with special 64 bit
    fcntl operations)

git-svn-id: trunk@13119 -
This commit is contained in:
Jonas Maebe 2009-05-09 19:47:59 +00:00
parent 1ce9d05b78
commit 53ad1bcabe
4 changed files with 94 additions and 2 deletions

2
.gitattributes vendored
View File

@ -7244,6 +7244,8 @@ tests/tbs/tb0557.pp svneol=native#text/plain
tests/tbs/tb0558.pp svneol=native#text/plain
tests/tbs/tb0559.pp svneol=native#text/plain
tests/tbs/tb0560.pp svneol=native#text/plain
tests/tbs/tb0561a.pp svneol=native#text/plain
tests/tbs/tb0561b.pp svneol=native#text/plain
tests/tbs/tb205.pp svneol=native#text/plain
tests/tbs/ub0060.pp svneol=native#text/plain
tests/tbs/ub0069.pp svneol=native#text/plain

View File

@ -137,14 +137,33 @@ type
TUtimBuf = UtimBuf;
pUtimBuf = ^UtimBuf;
kernel_off_t = clong;
kernel_loff_t = clonglong;
FLock = Record
l_type : cshort; { lock type: read/write, etc. }
l_whence: cshort; { type of l_start }
l_start : off_t; { starting offset }
l_len : off_t; { len = 0 means until end of file }
l_start : kernel_off_t; { starting offset }
l_len : kernel_off_t; { len = 0 means until end of file }
l_pid : pid_t; { lock owner }
{$ifdef cpusparc}
__pad : cshort;
{$endif}
End;
{$ifndef cpu64}
FLock64 = Record
l_type : cshort; { lock type: read/write, etc. }
l_whence: cshort; { type of l_start }
l_start : kernel_loff_t; { starting offset }
l_len : kernel_loff_t; { len = 0 means until end of file }
l_pid : pid_t; { lock owner }
{$ifdef cpusparc}
__pad : cshort;
{$endif}
End;
{$endif}
tms = packed Record
tms_utime : clock_t; { User CPU time }
tms_stime : clock_t; { System CPU time }

31
tests/tbs/tb0561a.pp Normal file
View File

@ -0,0 +1,31 @@
{ %norun }
{ %target=linux }
program test;
{$mode delphi}{$H+}
Uses cthreads, Classes, SysUtils, BaseUnix;
Const Fn = '/tmp/fpctest.lock';
F_RDLCK = 0;
F_WRLCK = 1;
F_UNLCK = 2;
Var F, I : Integer;
Region : FLock;
Begin
F := FpOpen (Fn, O_RDWR Or O_CREAT, $1B6); // $1B6 = o666
With Region Do Begin
l_type := F_RDLCK; l_whence := SEEK_SET;
l_start := 80; l_len := 1
End;
If FpFcntl (F, F_SETLK, Region) = -1 Then
begin
writeln(fpgeterrno);
WriteLn ('unable to apply readlock on 80'); // <-- Error
halt(1);
end;
FpClose (F);
End.

40
tests/tbs/tb0561b.pp Normal file
View File

@ -0,0 +1,40 @@
{ %target=linux }
program setup;
{$mode delphi}{$H+}
Uses cthreads, Classes, SysUtils, BaseUnix;
{ don't use current directory in case it's on a network share that does not
support locking
}
Const Fn = '/tmp/fpctest.lock';
F_RDLCK = 0;
F_WRLCK = 1;
F_UNLCK = 2;
Var F, I : Integer;
Region : FLock;
res: longint;
Begin
If FileExists (Fn) Then DeleteFile (Fn);
F := FpOpen (Fn, O_RDWR Or O_CREAT, $1B6); // $1B6 = o666
For I := 0 To 255 Do FpWrite (F, I, 1);
With Region Do Begin
l_type := F_WRLCK; l_whence := SEEK_SET;
l_start := 10; l_len := 20
End;
If FpFcntl (F, F_SETLK, Region) = -1 Then
begin
FpClose (F);
deletefile(fn);
halt(1);
end;
res:=executeprocess('./tb0561a','');
FpClose (F);
deletefile(fn);
if res<>0 then
halt(2);
End.