#include"tcpdl.h"

BOOL __saveds
copyfileclose( int task, BPTR source, BPTR target )
{
LONG nbytes;
   
   if( source==0 )
   {
      if( target!=0 )
         Close( target );
      
      return( FALSE );
   }
      
   if( target==0 )
   {
      Close( source );
      return( FALSE );
   }
      
   while( TRUE )
   {
      nbytes=Read( source, mmpoint->point[task].buffer, BUFSIZE );
      if( nbytes==0 )
      {
         Close( source );
         Close( target );
         return( TRUE );
      }
      
      if( nbytes==-1)
      {
         Close( source );
         Close( target );
         return( FALSE );
      }
      
      if( Write( target, mmpoint->point[task].buffer, nbytes)!=nbytes )
      {
         Close( source );
         Close( target );
         return( FALSE );
      }
   }
      
   return( FALSE ); /* should never happen */
}
