int main(int argc, char const *argv[])
{
int fd = 0;
int fdst = 0;
char tempbuff[1024] = {0};
ssize_t nret = 0;
if (argc != 3)
{
fprintf(stderr, "usage: ./a.out srcfile dstfile\n");
}
fd = open(argv[1], O_RDONLY);
if (-1 == fd)
{
perror("fail to open");
return -1;
}
fdst = open(argv[2], O_WRONLY | O_CREAT, 0664);
if (-1 == fdst)
{
perror("fail to open");
return -1;
}
while(1)
{
nret = read(fd, tempbuff, sizeof(tempbuff));
if (nret <= 0)
{
break;
}
write(fdst, tempbuff, nret);
}
close(fd);
close(fdst);
/* code */
return 0;
}
文本IO COPY
最新推荐文章于 2024-06-11 19:56:37 发布