zoneminder/src/zm_sendfile.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
799 B
C
Raw Normal View History

#ifndef ZM_SENDFILE_H
#define ZM_SENDFILE_H
#ifdef __cplusplus
extern "C" {
#endif
2015-02-24 22:20:55 +08:00
#ifdef HAVE_SENDFILE4_SUPPORT
#include <sys/sendfile.h>
int zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
2017-06-22 21:55:45 +08:00
int err;
2015-02-24 22:20:55 +08:00
2017-06-22 21:55:45 +08:00
err = sendfile(out_fd, in_fd, offset, size);
2020-09-08 01:28:45 +08:00
if ( err < 0 )
2017-06-22 21:55:45 +08:00
return -errno;
2015-02-24 22:20:55 +08:00
2017-06-22 21:55:45 +08:00
return err;
2015-02-24 22:20:55 +08:00
}
#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) {
2017-06-22 21:55:45 +08:00
int err;
err = sendfile(in_fd, out_fd, *offset, size, nullptr, &size, 0);
2017-06-22 21:55:45 +08:00
if (err && errno != EAGAIN)
return -errno;
2015-02-24 22:20:55 +08:00
2017-06-22 21:55:45 +08:00
if (size) {
*offset += size;
return size;
}
2015-02-24 22:20:55 +08:00
2017-06-22 21:55:45 +08:00
return -EAGAIN;
2015-02-24 22:20:55 +08:00
}
#else
#error "Your platform does not support sendfile. Sorry."
#endif
#ifdef __cplusplus
}
#endif
#endif