#include "misc.h"
#include <exec/types.h>
#include <libraries/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>

#define COPYBUFSIZE 8192

int copyfile(char *destination,char *source)
{	long fh1,fh2;
	UBYTE *copybuf;
	int len,error=0;

	if(copybuf=(UBYTE *)AllocMem(COPYBUFSIZE,MEMF_PUBLIC))
	{
		if(fh1=Open(source,MODE_OLDFILE))
		{
			if(fh2=Open(destination,MODE_NEWFILE))
			{
				while(len=Read(fh1,copybuf,COPYBUFSIZE))
					Write(fh2,copybuf,len);
				Close(fh2);
			}
			else
				error=-1;
			Close(fh1);
		}
		else
			error= -1;
		FreeMem(copybuf,COPYBUFSIZE);
	}
	else
		error= -1;
	return error;
}

