/* bm.copy opens file "bnch.test" (which can be created by running
bm.rw) and copies it block by block (512) to another file
("bnch.test1").  The copy terminates when the end of file is reached.
*/


char * ctime(); 
#define MAX 80 
#define MODE 0755 
#define READ_FILE "bnch.test" 
#define WRITE_FILE "bnch.test1" 
int t_start[2], t_end[2];
int total_time; 
char * gfiden; 
main () {

	char line[MAX];
	int repeat_for = 0;
	char *l;
	l = line;
        run_test();

}
getline(s, lim)
char *s;
int lim;
{
	int c,i;
	char *save;
	save = s;
	printf("ENTER THE NUMBER OF TIMES TO REPEAT: ");
	for (i=0; i<lim-1 && (c=getchar()) != 
		'\0' && c != '\n'; *save++ = c, ++i)
			;	
		if ((c  ==  '\0') && (i == 1))
			--save;
		*save = '\0';
		return(i);
}

run_test () 
{

int fdr, fdw;
char write_buf [512];
char read_buf [512];
char i;
int j;
int ctr;
int num_in, num_out;

	fdw = creat (WRITE_FILE, MODE);
	if (fdw < 0) 
	{
		printf (" error in create\n");
		return(0);
	}
	close(fdw);
	timeon();
	fdr = open(READ_FILE, 0);	
	fdw = open(WRITE_FILE,2);
	num_in = read(fdr, read_buf, 512);
	while (num_in == 512){
		
		num_out = write(fdw, read_buf, 512);
		if (num_out != 512) {
			printf(" write error: bytes = %d\n", num_out);
			break;
		}
		num_in = read(fdr,read_buf, 512);
	}
	close(fdr);
	close(fdw);
	timeoff();
}
timeon() {
	time(t_start);
	printf("COPY test starting: %s\n", ctime(t_start));
}

timeoff(){
	time(t_end);
	total_time += (32768 * (t_end[0] - t_start[0])) + ((t_end[1] - t_start[1]));
	printf("COPY test ending: %s\n", ctime(t_end));
	printf("total time = %d\n", total_time);
}
