* fixed solaris flock type

* fixed and enabled solaris flock implementation based on fcntl (although
    tests/test/units/sysutils/tfile2 still fails for solaris, because
    fcntl removes all locks as soon as you close a single file descriptor
    referring to a file, while flock doesn't)

git-svn-id: trunk@12632 -
This commit is contained in:
Jonas Maebe 2009-01-30 16:40:43 +00:00
parent 57ff980bc3
commit 6851d6d8e0
2 changed files with 18 additions and 14 deletions

View File

@ -66,6 +66,8 @@ TYPE
PStat = ^Stat; PStat = ^Stat;
flock = record flock = record
l_type : cshort; { lock type: read/write, etc. }
l_whence: cshort; { type of l_start }
{$ifdef 64bitfs} {$ifdef 64bitfs}
l_start : off64_t; { starting offset } l_start : off64_t; { starting offset }
l_len : off64_t; { len = 0 means until end of file } l_len : off64_t; { len = 0 means until end of file }
@ -73,9 +75,9 @@ TYPE
l_start : off_t; { starting offset } l_start : off_t; { starting offset }
l_len : off_t; { len = 0 means until end of file } l_len : off_t; { len = 0 means until end of file }
{$endif} {$endif}
l_sysid : cint;
l_pid : pid_t; { lock owner } l_pid : pid_t; { lock owner }
l_type : cshort; { lock type: read/write, etc. } l_pas : array[0..3] of clong;
l_whence: cshort; { type of l_start }
end; end;
TFlock = flock; TFlock = flock;
pFlock = ^flock; pFlock = ^flock;

View File

@ -74,29 +74,32 @@ begin
AssignPipe:=ret; AssignPipe:=ret;
end; end;
{ should probably be defined in ostypes.inc for all OSes }
const
F_RDLCK = 01; (* Read lock *)
F_WRLCK = 02; (* Write lock *)
F_UNLCK = 03; (* Remove lock(s) *)
Function fpFlock (fd,mode : longint) : cint; Function fpFlock (fd,mode : longint) : cint;
{
var var
fl : flock; fl : flock;
cmd : cint; cmd : cint;
}
begin begin
{
{ initialize the flock struct to set lock on entire file } { initialize the flock struct to set lock on entire file }
fillchar(fl,sizeof(fl),0); fillchar(fl,sizeof(fl),0);
{ In non-blocking lock, use F_SETLK for cmd, F_SETLKW otherwise } { In non-blocking lock, use F_SETLK for cmd, F_SETLKW otherwise }
if (operation and LOCK_NB)<>0 then if (mode and LOCK_NB)<>0 then
begin begin
cmd:=F_SETLK; cmd:=F_SETLK;
{ turn off this bit } { turn off this bit }
operation:=operation and not(LOCK_NB); mode:=mode and not(LOCK_NB);
end end
else else
cmd:=F_SETLKW; cmd:=F_SETLKW;
case operation of case mode of
LOCK_UN: LOCK_UN:
fl.l_type:=fl.l_type or F_UNLCK; fl.l_type:=fl.l_type or F_UNLCK;
LOCK_SH: LOCK_SH:
@ -105,15 +108,14 @@ Function fpFlock (fd,mode : longint) : cint;
fl.l_type:=fl.l_type or F_WRLCK; fl.l_type:=fl.l_type or F_WRLCK;
else else
begin begin
errno:=EINVAL; errno:=ESysEINVAL;
result:=-1 fpFlock:=-1;
exit; exit;
end; end;
end; end;
result:=fpFcntl(fd,cmd,@fl); fpFlock:=fpFcntl(fd,cmd,fl);
if (result=-1) and (errno=EACCES) if (fpFlock=-1) and (errno=ESysEACCES) then
errno:=EWOULDBLOCK; errno:=ESysEWOULDBLOCK;
}
end; end;