/* the bm.cu program creates, closes and unlinks the file "bnch.test"
for the number of times specified by the user response to the input
prompt */


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

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

}
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 (repeat_for) 
int repeat_for;  {

int fd;
char i;
int j;
int ctr;
int num_bytes;

	timeon();
	for (j = repeat_for; j > 0; j--) {
		fd = creat (FILE, MODE);
		if (fd < 0) 
		{
			printf (" error in create\n");
			return(0);
		}
		close(fd);
		unlink(FILE);
	}
	timeoff();

}
timeon() {
	time(t_start);
	printf("CREATE-UNLINK 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("CREATE-UNLINK  test ending: %s\n", ctime(t_end));
	printf("total time = %d\n", total_time);
}
