#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdlib.h>
#define SIZE 512
int main(int argc,char *argv[])
{
int in,out;
char buf[SIZE];
int nchars;
if(argc!=3)
{
perror("argc is error!");
}
if((in=open(argv[1],O_RDONLY))==-1)
{
perror("open 1 error!");
}
if((out=open(argv[2],O_RDWR|O_CREAT|O_EXCL))==-1)
{
perror("open 2 error!");
}
while((nchars=read(in,buf,SIZE))>0)
{
if(write(out,buf,nchars)!=nchars)
{
perror("write error!");
}
}
close(in);
close(out);
return 0;
}