1 /* sendfile -- copy data directly from one file descriptor to another
2 Copyright (C) 2002-2024 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, see
17 <https://www.gnu.org/licenses/>. */
19 #include <sys/sendfile.h>
24 /* Send COUNT bytes from file associated with IN_FD starting at OFFSET to
27 __sendfile64 (int out_fd
, int in_fd
, off64_t
*offset
, size_t count
)
29 /* We just do a vanilla io_read followed by a vanilla io_write here.
30 In theory the IN_FD filesystem can return us out-of-line data that
31 we then send out-of-line to the OUT_FD filesystem and no copying
32 takes place until those pages need to be flushed or packaged by
33 that filesystem (e.g. packetized by a network socket). However,
34 we momentarily consume COUNT bytes of our local address space,
35 which might blow if it's huge or address space is real tight. */
38 mach_msg_type_number_t datalen
= 0;
39 error_t err
= HURD_DPORT_USE (in_fd
,
40 __io_read (port
, &data
, &datalen
,
41 offset
? *offset
: (off_t
) -1,
48 err
= HURD_DPORT_USE (out_fd
, __io_write (port
, data
, datalen
,
49 (off_t
) -1, &nwrote
));
50 __munmap (data
, datalen
);
58 return __hurd_fail (err
);
60 strong_alias (__sendfile64
, sendfile64
)