{***********************************************************************}
{									}
{ __UnLocFil Unlock all or part of a file				}
{									}
{ procedure __UnLocFil(Handle : word; FileLen,FilePos : longint;	}
{					var ErrorCode : word);		}
{									}
{	      Handle	File handle.					}
{	      FilePos	The file position (or offset) of the section of }
{			the file to unlock.				}
{	      FileLen	Number of bytes to unlock			}
{	      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 release }
{			    a section not previously locked; the file	}
{			    locking position and length must be identi- }
{			    cal to the one specified in __LockFil.	}
{			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 __UnLocFil restores access to a region of a file that	}
{	      was formerly locked.  Areas to be unlocked must be	}
{	      precisely the same as those locked with the __LockFil	}
{	      procedure; moveover, locks must be released  with 	}
{	      __UnLocFil before the file is closed, because DOS 	}
{	      does not clean up locks when a program terminates or when }
{	      a file is closed. 					}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

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

  var
    DOSVersion : word;
    Reg        : registers;

  begin {__UnLocFil}

    { 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 := $5C01;		       { AH = $5C.     AL = 1		}
	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;	{__UnLocFil}
