#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char *argv[])
{
if(argc !=3 )
{
perror("open");
printf("usage: ./a.out srcfile destfile\n");
return -1;
}
int srcfd, destfd;
if((srcfd = open(argv[1], O_RDONLY)) == -1)
{
perror("srcfile open");
return -1;
}
if((destfd = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC)) == -1)
{
perror("destfile open");
return -1;
}
char arr[1024];
int ret;
while((ret =read(srcfd,arr,sizeof(arr)))!=0)
{
write(destfd,arr,ret);
}
close(srcfd);
close(destfd);
return 0;
}