2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / sendfile64.c
blob1f63d2a2f57a3244a444171d2c25c09d364e1544
1 /* sendfile -- copy data directly from one file descriptor to another
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <sys/sendfile.h>
21 #include <hurd.h>
22 #include <hurd/fd.h>
23 #include <sys/mman.h>
25 /* Send COUNT bytes from file associated with IN_FD starting at OFFSET to
26 descriptor OUT_FD. */
27 ssize_t
28 sendfile64 (int out_fd, int in_fd, off64_t *offset, size_t count)
30 /* We just do a vanilla io_read followed by a vanilla io_write here.
31 In theory the IN_FD filesystem can return us out-of-line data that
32 we then send out-of-line to the OUT_FD filesystem and no copying
33 takes place until those pages need to be flushed or packaged by
34 that filesystem (e.g. packetized by a network socket). However,
35 we momentarily consume COUNT bytes of our local address space,
36 which might blow if it's huge or address space is real tight. */
38 char *data = 0;
39 size_t datalen = 0;
40 error_t err = HURD_DPORT_USE (in_fd,
41 __io_read (port, &data, &datalen,
42 offset ? *offset : (off_t) -1,
43 count));
44 if (err == 0)
46 size_t nwrote;
47 if (datalen == 0)
48 return 0;
49 err = HURD_DPORT_USE (out_fd, __io_write (port, data, datalen,
50 (off_t) -1, &nwrote));
51 munmap (data, datalen);
52 if (err == 0)
54 if (offset)
55 *offset += datalen;
56 return nwrote;
59 return __hurd_fail (err);