#include <stdio.h>

#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
 
 
//#define SIZE 10
 
int mycopy(int argcc, char *argvv[], int bufsize);
 
 
int main(int argc, char *argv[])
{
    int i=0;
    int size=10;
 
    for(i=0; i<100; i++)
    {
        mycopy(argc,argv,size);
        size+=20;
    }
     return 0;
}
 
 
 
 
 
int mycopy(int argcc, char *argvv[], int bufsize)
{
    int src_file,dest_file;
    int nread;
    clock_t begin, end;
    double cost;
   // char buf[SIZE];
    char *buf = (char *)malloc(sizeof(char)*bufsize);
    if(NULL == buf)
    {
        perror("fail to malloc");
        exit(0);
    }
     begin = clock();
 
    if(argcc < 3)
    {printf("arg is not enough, please input 3 args\n");
    exit(0);
    }
 
    src_file = open(argvv[1],O_RDONLY);
 
    dest_file = open(argvv[2],O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
   
    
    while( (nread = read(src_file, buf, bufsize ))!=0 )
    {
        if(nread != -1)
        {
            write(dest_file, buf, nread);
        }
        else
        {perror("fali");}
    }
    free(buf);
    buf=NULL;
    close(src_file);
    close(dest_file);
    end = clock();
    cost = (double)(end - begin)/CLOCKS_PER_SEC;
 
 
    printf("buf size is %5d, ",bufsize);    
    printf("used %f seconds\n",cost);
    return 0;
}