Cygwin上没有sys / sendfile.h?

时间:2012-11-01 17:49:18

标签: c compiler-errors cygwin

我正在尝试在Cygwin上编译一些需要sendfile.h的C代码。当我尝试编译时,它给了我

fatal error: sys/sendfile.h: No such file or directory
compilation terminated.

我该如何解决这个问题?我是否必须转移到Linux平台?我在Cygwin上安装了gcc4.5。

2 个答案:

答案 0 :(得分:2)

与上述评论一样,sendfile不是POSIX,而是来自 sendfile(2)

  

sendfile()在一个文件描述符和另一个文件描述符之间复制数据。   因为这种复制是在内核中完成的,所以sendfile()更多   比read(2)和write(2)的组合有效   需要与用户空间之间传输数据。

这意味着它基本上是read()后跟write(),因此自己实施它会相对容易。

答案 1 :(得分:0)

我删除了

#include <sys/sendfile.h>

和 重写

sendfile(write_fd, read_fd, &offset, stat_buf.st_size);

read(read_fd, &offset, stat_buf.st_size);
write(write_fd, &offset, stat_buf.st_size);

,效果很好。 谢谢。