#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define BUFSIZE  1024

main(int argc, char * argv[])
{
    int fd_s,fd_t;
    char buf[BUFSIZE];
    int num;
    if(argc!=3)
    {
		printf("the format must be: cp file_src file_des");
		exit(EXIT_FAILURE);
    }
	if((fd_s=open(argv[1],O_RDONLY))==-1)
    {
		perror("open source file");
		exit(EXIT_FAILURE);
    }
    if((fd_t=creat(argv[2],0644))==-1)
    {
		perror("open2");
		exit(EXIT_FAILURE);
    }	
    while((num=read(fd_s,buf,BUFSIZE))>0)
		if(write(fd_t,buf,num)==-1)
		{
			perror("write");
			exit(EXIT_FAILURE);
		}
	if(num==-1)
	{
		perror("read");
		exit(EXIT_FAILURE);
	}
	if(close(fd_s)==-1||close(fd_t)==-1)
	{
		perror("close");
		exit(EXIT_FAILURE);
	}
}

