{***********************************************************************}
{									}
{ __FlushFil  Force pending output to the device			}
{									}
{ procedure __FlushFil(Handle : word; var ErrorCode : word);		}
{									}
{   Handle    The handle of an opened file.  For a Turbo Pascal file,	}
{	      use __HandlFil to return the handle.			}
{   ErrorCode The returned DOS error code.				}
{	      (0) Pending output successfully written to the device.	}
{	      (4) Not enough handles; too many files are already open.	}
{		  __FlushFil uses the DOS duplicate handle function	}
{		  ($45) to force the pending output which requires an	}
{		  additional file handle.  This error can occur if all	}
{		  file handles are already used.			}
{	      (6) Handle is not the handle of an open file.		}
{									}
{ Description __FlushFil flushes the DOS buffer associated with a given }
{	      file handle.  It is useful for output files to make sure	}
{	      that the data is really on the disk, instead of merely in }
{	      a DOS memory buffer.  For text files, the the Turbo Pascal}
{	      Flush procedure should be used to force data from the	}
{	      internal Turbo Pascal buffer before calling __FlushFil.	}
{	      The directory entry for the file is also updated. 	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

procedure __FlushFil(Handle : word; var ErrorCode : word);

  var
    Reg : registers;

  begin {__FlushFil}

    with Reg do
      begin
	AH := $45;		       { DUP a handle; returned handle	}
	BX := Handle;		       { is in AX.			}
	Intr(_DOS,Reg);
	if ((Flags and FCarry) <> 0) then
	     ErrorCode := AX
	else			       { Close the returned handle to	}
	   begin		       { flush the buffers and update	}
	     BX := AX;		       { the directory. 		}
	     AH := $3E; 	       { Close a handle 		}
	     Intr(_DOS,Reg);
	     if ((Flags and FCarry) <> 0) then
		ErrorCode := AX
	     else
		ErrorCode := 0
	   end
      end;

  end;	{__FlushFil}
