我创建文件1.txt
2.txt
并将一些内容写入1.txt
。
然后我使用下面的代码,并要复制内容到2.txt
。
但它不起作用。 2.txt
中没有任何内容。sendfile不复制文件内容
你能解释我的错误吗?
int main()
{
int fd1 = open("1.txt",O_RDWR);
int fd2 = open("2.txt",O_RDWR);
struct stat stat_buf ;
fstat(fd1,&stat_buf);
ssize_t size = sendfile(fd1,fd2,0,stat_buf.st_size);
cout<<"fd1 size:"<<stat_buf.st_size<<endl; //output 41
cout<<strerror(errno)<<endl; //output success
close(fd1);
close(fd2);
return 0;
}
这标记 'C',但很明显,使用C++流。不要这样做。 – unwind
已移至C++。 ;) –
因为我使用linux C API - “sendfile”,所以我taaged“C”。我会关注这一点,谢谢! – Tengchao