#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
int fd_r = open("./1.png",O_RDONLY);
if (fd_r < 0)
{
perror("open");
return -1;
}
int fd_w = open("copy.png",O_WRONLY|O_CREAT|O_TRUNC,0777);
if (fd_w < 0)
{
perror("open");
return -1;
}
char buf[20]="";
ssize_t res = 0;
while(1)
{
res = read(fd_r,buf,sizeof(buf));
if (0 == res)
{
printf("文件读取完毕\n");
break;
}
else if(res < 0)
{
perror("read");
}
write(fd_w,buf,res);
}
//关闭文件
close(fd_r);
close(fd_w);
return 0;
}
3551



被折叠的 条评论
为什么被折叠?



