Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change behaviour of sendfile(2) on FreeBSD to mimic Linux #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/lib/sendfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ int sendfile(int, int, off_t, off_t *, void *, int);
#endif

#include <stdlib.h>
# if defined(__FreeBSD__) || defined(__DragonFly__)
#include <errno.h>
# endif

DSO_PUBLIC ssize_t
lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes)
Expand All @@ -46,8 +49,13 @@ lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes)
# if defined(__linux__)
off_t off = offset;
return (ssize_t) sendfile(out_fd, in_fd, &off, nbytes);
# elif defined(__FreeBSD__)
return (ssize_t) sendfile(in_fd, out_fd, offset, nbytes, NULL, NULL, SF_MNOWAIT);
# elif defined(__FreeBSD__) || defined(__DragonFly__)
off_t sbytes;
int res = sendfile(in_fd, out_fd, offset, nbytes, NULL, &sbytes, 0);
if (res == -1 && errno == EAGAIN)
res = 0;
if (res == 0) res = sbytes;
return res;
# elif defined(__DragonFly__)
return (ssize_t) sendfile(in_fd, out_fd, offset, nbytes, NULL, NULL, 0);
# elif defined(__APPLE__)
Expand Down