Wrap up version 1.3.3.
[minidlna.git] / sendfile.h
blob1ea50c520ef2398403aed490b3e1ceec9131fad1
1 /* MiniDLNA media server
2 * Copyright (C) 2013 NETGEAR
4 * This file is part of MiniDLNA.
6 * MiniDLNA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * MiniDLNA is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
18 #if defined(HAVE_LINUX_SENDFILE_API)
20 #include <sys/sendfile.h>
22 int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
24 return sendfile(sock, sendfd, offset, len);
27 #elif defined(HAVE_DARWIN_SENDFILE_API)
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/uio.h>
33 int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
35 int ret;
37 ret = sendfile(sendfd, sock, *offset, &len, NULL, 0);
38 *offset += len;
40 return ret;
43 #elif defined(HAVE_FREEBSD_SENDFILE_API)
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <sys/uio.h>
49 int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
51 int ret;
52 size_t nbytes = len;
54 ret = sendfile(sendfd, sock, *offset, nbytes, NULL, &len, 0);
55 *offset += len;
57 return ret;
60 #else
62 #include <errno.h>
64 int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
66 errno = EINVAL;
67 return -1;
70 #endif