#include<myhead.h>
pthread_mutex_t fastmutex;
typedef struct {
char src_path[50];
char des_path[50];
int start;
int len;
}file_path;
void *fun(void *file){
file_path *file1=(file_path *)file;
int fd1=open(file1->src_path,O_RDONLY);
int fd2=open(file1->des_path,O_WRONLY);
lseek(fd1,file1->start,SEEK_SET);
lseek(fd2,file1->start,SEEK_SET);
int buff[256];
int sum=0;
int half=file1->len;
while(1){
int res=read(fd1,buff,sizeof(buff));
sum+=res;
if(res<=0||sum>half){
write(fd2,buff,res-(sum-half));
break;
}
write(fd2,buff,res);
}
}
int main(int argc, const char *argv[])
{
if(argc!=3){
return -1;
}
pthread_mutex_init(&fastmutex,NULL);
file_path file1,file2;
strcpy(file1.src_path,argv[1]);
strcpy(file1.des_path,argv[2]);
int fd1=open(argv[1],O_RDONLY);
int fd2=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0664);
int len=lseek(fd1,0,SEEK_END);
int half=len/2;
file1.start=0;
file1.len=half;
file2=file1;
file2.start=len-half;
close(fd1);
close(fd2);
pthread_t pid1,pid2;
pthread_create(&pid1,NULL,fun,&file1);
pthread_create(&pid2,NULL,fun,&file2);
pthread_join(pid1,NULL);
pthread_join(pid2,NULL);
return 0;
}
