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.
13 #include <sys/types.h>
15 #include <sys/socket.h>
18 #include <atalk/adouble.h>
22 #include "ad_private.h"
24 static int _ad_sendfile_dummy;
26 #if defined(HAVE_SENDFILE_READ) || defined(HAVE_SENDFILE_WRITE)
27 static __inline__ int ad_sendfile_init(const struct adouble *ad,
28 const int eid, off_t *off,
34 *off = ad_size(ad, eid) - *off;
36 if (eid == ADEID_DFORK) {
39 *off += ad_getentryoff(ad, eid);
48 /* read from adouble file and write to socket. sendfile doesn't change
49 * the file pointer position. */
50 #ifdef HAVE_SENDFILE_READ
51 ssize_t ad_readfile(const struct adouble *ad, const int eid,
52 const int sock, off_t off, const size_t len)
57 fd = ad_sendfile_init(ad, eid, &off, 0);
59 cc = sendfile(sock, fd, &off, len);
63 if (sendfile(fd, sock, off, len, NULL, &cc, 0) < 0)
72 #ifdef HAVE_SENDFILE_WRITE
73 /* read from a socket and write to an adouble file */
74 ssize_t ad_writefile(struct adouble *ad, const int eid,
75 const int sock, off_t off, const int end,
82 fd = ad_sendfile_init(ad, eid, &off, end);
83 if ((cc = sendfile(fd, sock, &off, len)) < 0)
86 if ((eid != ADEID_DFORK) && (off > ad_getentrylen(ad, eid)))
87 ad_setentrylen(ad, eid, off);