2 * $Id: ad_sendfile.c,v 1.11 2010-01-21 14:14:49 didg Exp $
4 * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
5 * All rights reserved. See COPYRIGHT.
7 * NOTE: the following uses the fact that sendfile() only exists on
8 * machines with SA_RESTART behaviour. this is all very machine specific.
10 * sendfile chainsaw from samba.
11 Unix SMB/Netbios implementation.
13 sendfile implementations.
14 Copyright (C) Jeremy Allison 2002.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #endif /* HAVE_CONFIG_H */
36 #include <atalk/adouble.h>
40 #include <sys/socket.h>
45 #include <atalk/logger.h>
46 #include "ad_private.h"
48 #if defined(SENDFILE_FLAVOR_LINUX)
49 #include <sys/sendfile.h>
51 ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count)
53 return sendfile(tofd, fromfd, offset, count);
56 #elif defined(SENDFILE_FLAVOR_SOLARIS)
57 #include <sys/sendfile.h>
59 ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count)
61 return sendfile(tofd, fromfd, offset, count);
64 #elif defined(SENDFILE_FLAVOR_BSD )
65 #include <sys/types.h>
66 #include <sys/socket.h>
68 ssize_t sys_sendfile(int tofd, int fromfd, off_t *offset, size_t count)
73 ret = sendfile(fromfd, tofd, *offset, count, NULL, &len, 0);
84 ssize_t sys_sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
86 /* No sendfile syscall. */
92 /* ------------------------------- */
93 int ad_readfile_init(const struct adouble *ad,
94 const int eid, off_t *off,
100 *off = ad_size(ad, eid) - *off;
102 if (eid == ADEID_DFORK) {
103 fd = ad_data_fileno(ad);
105 *off += ad_getentryoff(ad, eid);
106 fd = ad_reso_fileno(ad);
113 /* ------------------------ */
115 #ifdef HAVE_SENDFILE_WRITE
116 /* read from a socket and write to an adouble file */
117 ssize_t ad_writefile(struct adouble *ad, const int eid,
118 const int sock, off_t off, const int end,
125 fd = ad_sendfile_init(ad, eid, &off, end);
126 if ((cc = sys_sendfile(fd, sock, &off, len)) < 0)
129 if ((eid != ADEID_DFORK) && (off > ad_getentrylen(ad, eid)))
130 ad_setentrylen(ad, eid, off);
133 #endif /* __linux__ */
135 #endif /* HAVE_SENDFILE_WRITE */