2 * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
3 * All rights reserved. See COPYRIGHT.
5 * NOTE: the following uses the fact that sendfile() only exists on
6 * machines with SA_RESTART behaviour. this is all very machine specific.
17 #include <sys/types.h>
19 #include <sys/socket.h>
22 #include <atalk/adouble.h>
26 #include "ad_private.h"
28 static int _ad_sendfile_dummy;
30 #if defined(HAVE_SENDFILE_READ) || defined(HAVE_SENDFILE_WRITE)
31 static __inline__ int ad_sendfile_init(const struct adouble *ad,
32 const int eid, off_t *off,
38 *off = ad_size(ad, eid) - *off;
40 if (eid == ADEID_DFORK) {
43 *off += ad_getentryoff(ad, eid);
52 /* read from adouble file and write to socket. sendfile doesn't change
53 * the file pointer position. */
54 #ifdef HAVE_SENDFILE_READ
55 ssize_t ad_readfile(const struct adouble *ad, const int eid,
56 const int sock, off_t off, const size_t len)
61 fd = ad_sendfile_init(ad, eid, &off, 0);
63 cc = sendfile(sock, fd, &off, len);
67 if (sendfile(fd, sock, off, len, NULL, &cc, 0) < 0)
76 #ifdef HAVE_SENDFILE_WRITE
77 /* read from a socket and write to an adouble file */
78 ssize_t ad_writefile(struct adouble *ad, const int eid,
79 const int sock, off_t off, const int end,
86 fd = ad_sendfile_init(ad, eid, &off, end);
87 if ((cc = sendfile(fd, sock, &off, len)) < 0)
90 if ((eid != ADEID_DFORK) && (off > ad_getentrylen(ad, eid)))
91 ad_setentrylen(ad, eid, off);