1/* MiniDLNA media server 2 * Copyright (C) 2013 NETGEAR 3 * 4 * This file is part of MiniDLNA. 5 * 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. 9 * 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. 14 * 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/>. 17 */ 18#if defined(HAVE_LINUX_SENDFILE_API) 19 20#include <sys/sendfile.h> 21 22int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len) 23{ 24 return sendfile(sock, sendfd, offset, len); 25} 26 27#elif defined(HAVE_DARWIN_SENDFILE_API) 28 29#include <sys/types.h> 30#include <sys/socket.h> 31#include <sys/uio.h> 32 33int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len) 34{ 35 int ret; 36 37 ret = sendfile(sendfd, sock, *offset, &len, NULL, 0); 38 *offset += len; 39 40 return ret; 41} 42 43#elif defined(HAVE_FREEBSD_SENDFILE_API) 44 45#include <sys/types.h> 46#include <sys/socket.h> 47#include <sys/uio.h> 48 49int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len) 50{ 51 int ret; 52 size_t nbytes = len; 53 54 ret = sendfile(sendfd, sock, *offset, nbytes, NULL, &len, SF_MNOWAIT); 55 *offset += len; 56 57 return ret; 58} 59 60#else 61 62#include <errno.h> 63 64int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len) 65{ 66 errno = EINVAL; 67 return -1; 68} 69 70#endif 71