Reputation: 1817
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?
Upvotes: 7
Views: 11106
Reputation: 40337
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>
Upvotes: 8
Reputation: 409136
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.
Upvotes: 6
Reputation: 6020
On OSX sendfile is defined in socket.h. So you need to include socket.h instead of sys/sendfile.h
Upvotes: 2
Reputation: 14619
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>
Upvotes: 4