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?
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>
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With