#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <libgen.h>
#include <fcntl.h>
#define BUFFER_SIZE 4096
int main(int argc,char* argv[])
{
if(argc != 3)
{
printf("Usage:%s src dest\n",basename(argv[0]));
exit(-1);
}
char* szSrc = argv[1];
char* szDest = argv[2];
if(access(szSrc,F_OK)!=0)
printf("file is not exists.\n"),exit(-1);
int srcfd = open(szSrc,O_RDWR);
if(srcfd == -1)
perror("open"),exit(-1);
int destfd = open(szDest,O_RDWR|O_CREAT|O_TRUNC,0664);
if(destfd == -1)
perror("open"),exit(-1);
ssize_t size = -1;
char buf[BUFFER_SIZE];
while((size=read(srcfd,buf,4096)))
write(destfd,buf,size);
printf("%s cp to %s success!\n",szSrc,szDest);
return 0;
}
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <libgen.h>
#include <fcntl.h>
#define BUFFER_SIZE 4096
int main(int argc,char* argv[])
{
if(argc != 3)
{
printf("Usage:%s src dest\n",basename(argv[0]));
exit(-1);
}
char* szSrc = argv[1];
char* szDest = argv[2];
if(access(szSrc,F_OK)!=0)
printf("file is not exists.\n"),exit(-1);
int srcfd = open(szSrc,O_RDWR);
if(srcfd == -1)
perror("open"),exit(-1);
int destfd = open(szDest,O_RDWR|O_CREAT|O_TRUNC,0664);
if(destfd == -1)
perror("open"),exit(-1);
ssize_t size = -1;
char buf[BUFFER_SIZE];
while((size=read(srcfd,buf,4096)))
write(destfd,buf,size);
printf("%s cp to %s success!\n",szSrc,szDest);
return 0;
}