{***********************************************************************}
{									}
{ __LockFil  Lock all or part of a file 				}
{									}
{ procedure __LockFil(Handle: word; FilePos,FileLen : longint;		}
{				      var ErrorCode : word);		}
{									}
{	      Handle	File handle.					}
{	      FilePos	The file position (or offset) to begin locking	}
{	      FileLen	Number of bytes to lock 			}
{	      ErrorCode The returned DOS error status code:		}
{			(0) Operation successful.			}
{			(1) Illegal function request (this is avail-	}
{			    able only for DOS 3.10).			}
{			(6) Invalid file handle.			}
{			(33) Lock violation.  You are trying to lock a	}
{			    section already locked.			}
{			If DOS version 3.0 or later is used, a call to	}
{			 __RetErUtl can be made to return more informa- }
{			tion on the error.				}
{									}
{ Description __LockFil excludes other read/write processes from access }
{	      to a region of a file. This procedure provides a simple	}
{	      mechanism for excluding other processes from a section	}
{	      of the file.  If another process tries to access a locked }
{	      region, it will retry three times (the value can be	}
{	      reset using __RetryFil), but if it fails, a general error }
{	      condition is set.  Locked regions can be anywhere in the	}
{	      logical file, and locking beyond the end of the file is	}
{	      not an error.  To lock the entire file, you can specify	}
{	      the maximum file length (32M bytes) starting at offset 0. }
{									}
{	      Access to file locks is not duplicated in a child process }
{	      (that is, they cannot be released in a child process).	}
{	      Also, file locks are not released when the file is	}
{	      closed, and if not, unpredictable results may occur.  All }
{	      file locks should be released (see __UnLocFil) before	}
{	      the file is closed and the program terminates.		}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

procedure __LockFil(Handle : word; FilePos,FileLen : longint;
				     var ErrorCode : word);

  var
    DOSVersion : word;
    Reg        : registers;

  begin {__LockFil}

    { This function is available only for DOS 3.10 and later.  If an	}
    { earlier version is used, set the error code to 1 and exit.	}

    DOSVersion := __2WordSup(_DOSMajorVer,_DOSMinorVer);
    if (DOSVersion < $030A) then
       begin
	 ErrorCode := 1;
	 Exit
       end;

    with Reg do 		       { Lock/Unlock file access	}
      begin
	AX := $5C00;		       { AH = $5C.     AL = 0		}
	BX := Handle;
	CX := __HiWrdSup(FilePos);
	DX := __LoWrdSup(FilePos);
	SI := __HiWrdSup(FileLen);
	DI := __LoWrdSup(FileLen);
	Intr(_DOS,Reg);
	if ((Flags and FCarry) <> 0) then
	     ErrorCode := AX
	else
	     ErrorCode := 0
      end

  end;	{__LockFil}
