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

View File

@ -74,29 +74,32 @@ begin
AssignPipe:=ret;
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;
{
var
fl : flock;
cmd : cint;
}
begin
{
{ initialize the flock struct to set lock on entire file }
fillchar(fl,sizeof(fl),0);
{ 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
cmd:=F_SETLK;
{ turn off this bit }
operation:=operation and not(LOCK_NB);
mode:=mode and not(LOCK_NB);
end
else
cmd:=F_SETLKW;
case operation of
case mode of
LOCK_UN:
fl.l_type:=fl.l_type or F_UNLCK;
LOCK_SH:
@ -105,15 +108,14 @@ Function fpFlock (fd,mode : longint) : cint;
fl.l_type:=fl.l_type or F_WRLCK;
else
begin
errno:=EINVAL;
result:=-1
errno:=ESysEINVAL;
fpFlock:=-1;
exit;
end;
end;
result:=fpFcntl(fd,cmd,@fl);
fpFlock:=fpFcntl(fd,cmd,fl);
if (result=-1) and (errno=EACCES)
errno:=EWOULDBLOCK;
}
if (fpFlock=-1) and (errno=ESysEACCES) then
errno:=ESysEWOULDBLOCK;
end;