1 | /* Transfer data between file descriptors. Linux version. |
2 | Copyright (C) 2011-2023 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <sys/sendfile.h> |
20 | #include <stddef.h> |
21 | #include <errno.h> |
22 | #include <sysdep.h> |
23 | |
24 | #ifndef __OFF_T_MATCHES_OFF64_T |
25 | |
26 | /* Send COUNT bytes from file associated with IN_FD starting at OFFSET to |
27 | descriptor OUT_FD. */ |
28 | ssize_t |
29 | sendfile (int out_fd, int in_fd, off_t *offset, size_t count) |
30 | { |
31 | # ifdef __NR_sendfile |
32 | return INLINE_SYSCALL_CALL (sendfile, out_fd, in_fd, offset, count); |
33 | # else |
34 | __off64_t off64; |
35 | int rc; |
36 | |
37 | if (offset != NULL) |
38 | { |
39 | if (*offset < 0 || (off_t) (*offset + count) < 0) |
40 | { |
41 | __set_errno (EINVAL); |
42 | return -1; |
43 | } |
44 | off64 = *offset; |
45 | } |
46 | |
47 | rc = INLINE_SYSCALL_CALL (sendfile64, out_fd, in_fd, offset ? &off64 : NULL, |
48 | count); |
49 | if (offset) |
50 | *offset = off64; |
51 | return rc; |
52 | # endif |
53 | } |
54 | |
55 | #endif |
56 | |