Skip to content

Commit

Permalink
Fix lfp_sendfile() to always return the number of transferred bytes.
Browse files Browse the repository at this point in the history
Previously, the return value on DragonFlyBSD/FreeBSD/OSX was always 0
on success.

Thanks to Vasily Postnicov for the bug report.

Close #18
  • Loading branch information
sionescu committed Dec 2, 2021
1 parent 040cd8f commit fc5bbe4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib/sendfile.c
Expand Up @@ -38,6 +38,7 @@ int sendfile(int, int, off_t, off_t *, void *, int);
#endif

#include <stdlib.h>
#include <errno.h>

DSO_PUBLIC ssize_t
lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes)
Expand All @@ -46,18 +47,21 @@ 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(__DragonFly__)
return (ssize_t) sendfile(in_fd, out_fd, offset, nbytes, NULL, NULL, 0);
# elif defined(__FreeBSD__) || defined(__DragonFly__)
off_t sbytes;
int res = sendfile(in_fd, out_fd, offset, nbytes, NULL, &sbytes, 0);
if (res == 0) { return sbytes; }
return res;
# elif defined(__APPLE__)
off_t len = nbytes;
return (ssize_t) sendfile(in_fd, out_fd, offset, &len, NULL, 0);
int res = sendfile(in_fd, out_fd, offset, &len, NULL, 0);
if (res == 0) { return len; }
return -1;
# else
# error "It appears that this OS has sendfile(), but LFP doesn't use it at the moment"
# error "Please send an email to iolib-devel@common-lisp.net"
# endif
#else
return ENOSYS;
SYSERR(ENOSYS);
#endif
}

0 comments on commit fc5bbe4

Please sign in to comment.