Browse Source

* Introduce fmShareNoLocking to disable locking of file descriptors on unix

Michaël Van Canneyt 1 year ago
parent
commit
e79f5ef577
2 changed files with 7 additions and 3 deletions
  1. 2 0
      rtl/objpas/sysutils/filutilh.inc
  2. 5 3
      rtl/unix/sysutils.pp

+ 2 - 0
rtl/objpas/sysutils/filutilh.inc

@@ -199,6 +199,8 @@ Const
   fmShareDenyWrite = $0020;
   fmShareDenyWrite = $0020;
   fmShareDenyRead  = $0030;
   fmShareDenyRead  = $0030;
   fmShareDenyNone  = $0040;
   fmShareDenyNone  = $0040;
+  // internal to FPC
+  fmShareNoLocking = $0100;
 
 
   { File seek origins }
   { File seek origins }
   fsFromBeginning = 0;
   fsFromBeginning = 0;

+ 5 - 3
rtl/unix/sysutils.pp

@@ -471,7 +471,8 @@ Function FileOpen (Const FileName : RawbyteString; Mode : Integer) : Longint;
 
 
 begin
 begin
   FileOpen:=FileOpenNoLocking(FileName, Mode);
   FileOpen:=FileOpenNoLocking(FileName, Mode);
-  FileOpen:=DoFileLocking(FileOpen, Mode);
+  if (Mode and fmShareNoLocking)=0 then
+    FileOpen:=DoFileLocking(FileOpen, Mode);
 end;
 end;
 
 
 function FileFlush(Handle: THandle): Boolean;
 function FileFlush(Handle: THandle): Boolean;
@@ -513,7 +514,7 @@ begin
     (which we can by definition) }
     (which we can by definition) }
   fd:=FileOpenNoLocking(FileName,ShareMode);
   fd:=FileOpenNoLocking(FileName,ShareMode);
   { the file exists, check whether our locking request is compatible }
   { the file exists, check whether our locking request is compatible }
-  if fd>=0 then
+  if (fd>=0) and ((ShareMode and fmShareNoLocking)=0) then
     begin
     begin
       Result:=DoFileLocking(fd,ShareMode);
       Result:=DoFileLocking(fd,ShareMode);
       FileClose(fd);
       FileClose(fd);
@@ -523,7 +524,8 @@ begin
     end;
     end;
   { now create the file }
   { now create the file }
   Result:=FileCreate(FileName,Rights);
   Result:=FileCreate(FileName,Rights);
-  Result:=DoFileLocking(Result,ShareMode);
+  if (ShareMode and fmShareNoLocking)=0 then
+    Result:=DoFileLocking(Result,ShareMode);
 end;
 end;