Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sys/sendfile.h not found GCC

I am using Mac OS 10.6.7,

The gcc compiler was already there when I bought Mac. but when I try to include sys/sendfile.h #include<sys/sendfile.h>

it throws an error

sys/sendfile.h: No such file or directory.

But this program works correctly in ubuntu GCC Compiler. Any idea how to fix this?

like image 719
Geo Paul Avatar asked Nov 24 '11 05:11

Geo Paul


3 Answers

sendfile() is ultimately a kernel capability not a library or compiler one, and to quote the linux manpage, "Other Unix systems implement sendfile() with different semantics and prototypes. It should not be used in portable programs."

There used to be a link to the applicable OSX/Darwin manpage for sendfile here, but Apple keeps moving their documentation, so you'll have to find that on your own.

And indeed the linux manpage warning is accurate - the prototypes are different:

OSX:

int sendfile(int fd, int s, off_t offset, off_t *len, struct sf_hdtr *hdtr, int flags);

Linux:

ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);

So you will have some re-writing to do.

The osx includes are on that man page, but for completeness:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
like image 97
Chris Stratton Avatar answered Nov 04 '22 19:11

Chris Stratton


According to the Linux manual page:

Not specified in POSIX.1-2001, or other standards.

Other UNIX systems implement sendfile() with different semantics and prototypes. It should not be used in portable programs.

I'm not sure about OSX, but it seems you have to do a little digging yourself to find it.

like image 6
Some programmer dude Avatar answered Nov 04 '22 21:11

Some programmer dude


Are you looking for sendfile(2)? If so, it's not in sys/sendfile.h:

The OS X Developer Library states you should include these:

 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
like image 4
Brian Cain Avatar answered Nov 04 '22 21:11

Brian Cain