使用C语言实现Linux环境下终端拷贝函数
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char buf[1024];
int ret = 0;
int fd1 = open(argv[1],O_RDONLY);
int fd2 = open(argv[2],O_RDWR | O_TRUNC | O_CREAT, 0664);
while((ret = read(fd1, buf, sizeof(buf))))
{
write(fd2,buf,ret);
}
close(fd1);
close(fd2);
printf("close ok...\n");
return 0;
}