37 lines
747 B
C
37 lines
747 B
C
#ifndef ZM_SENDFILE_H
|
|
#define ZM_SENDFILE_H
|
|
|
|
#ifdef HAVE_SENDFILE4_SUPPORT
|
|
#include <sys/sendfile.h>
|
|
int zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
|
|
int err;
|
|
|
|
err = sendfile(out_fd, in_fd, offset, size);
|
|
if ( err < 0 )
|
|
return -errno;
|
|
|
|
return err;
|
|
}
|
|
#elif HAVE_SENDFILE7_SUPPORT
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/uio.h>
|
|
int zm_sendfile(int out_fd, int in_fd, off_t *offset, off_t size) {
|
|
int err;
|
|
err = sendfile(in_fd, out_fd, *offset, size, nullptr, &size, 0);
|
|
if (err && errno != EAGAIN)
|
|
return -errno;
|
|
|
|
if (size) {
|
|
*offset += size;
|
|
return size;
|
|
}
|
|
|
|
return -EAGAIN;
|
|
}
|
|
#else
|
|
#error "Your platform does not support sendfile. Sorry."
|
|
#endif
|
|
|
|
#endif // ZM_SENDFILE_H
|