1 .\" This man page is Copyright (C) 1998 Pawel Krawczyk.
3 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
10 .\" $Id: sendfile.2,v 1.5 1999/05/18 11:54:11 freitag Exp $
11 .\" 2000-11-19 bert hubert <ahu@ds9a.nl>: in_fd cannot be socket
14 .\" updated description of in_fd and out_fd for 2.6
15 .\" Various wording and formatting changes
17 .\" 2005-03-31 Martin Pool <mbp@sourcefrog.net> mmap() improvements
19 .TH sendfile 2 (date) "Linux man-pages (unreleased)"
21 sendfile \- transfer data between file descriptors
24 .RI ( libc ", " \-lc )
27 .B #include <sys/sendfile.h>
29 .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", \
30 off_t *_Nullable " offset ,
31 .BI " size_t" " count" );
32 .\" The below is too ugly. Comments about glibc versions belong
33 .\" in the notes, not in the header.
35 .\" .B #include <features.h>
36 .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2
37 .\" .B #include <sys/sendfile.h>
39 .\" .B #include <sys/types.h>
40 .\" .B /* No system prototype before glibc 2.1. */
41 .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
42 .\" offset ", size_t" " count" )
48 copies data between one file descriptor and another.
49 Because this copying is done within the kernel,
51 is more efficient than the combination of
55 which would require transferring data to and from user space.
58 should be a file descriptor opened for reading and
60 should be a descriptor opened for writing.
64 is not NULL, then it points
65 to a variable holding the file offset from which
67 will start reading data from
71 returns, this variable
72 will be set to the offset of the byte following the last byte that was read.
77 does not modify the file offset of
79 otherwise the file offset is adjusted to reflect
80 the number of bytes read from
85 is NULL, then data will be read from
87 starting at the file offset,
88 and the file offset will be updated by the call.
91 is the number of bytes to copy between the file descriptors.
95 argument must correspond to a file which supports
98 (i.e., it cannot be a socket).
100 In Linux kernels before 2.6.33,
102 must refer to a socket.
103 Since Linux 2.6.33 it can be any file.
104 If it is a regular file, then
106 changes the file offset appropriately.
108 If the transfer was successful, the number of bytes written to
111 Note that a successful call to
113 may write fewer bytes than requested;
114 the caller should be prepared to retry the call if there were unsent bytes.
117 On error, \-1 is returned, and
119 is set to indicate the error.
123 Nonblocking I/O has been selected using
125 and the write would block.
128 The input file was not opened for reading or the output file
129 was not opened for writing.
135 Descriptor is not valid or locked, or an
137 operation is not available for
148 This is not currently supported by
152 Unspecified error while reading from
156 Insufficient memory to read from
161 is too large, the operation would result in exceeding the maximum size of either
162 the input file or the output file.
166 is not NULL but the input file is not seekable.
169 first appeared in Linux 2.2.
172 is present since glibc 2.1.
174 Not specified in POSIX.1-2001, nor in other standards.
176 Other UNIX systems implement
178 with different semantics and prototypes.
179 It should not be used in portable programs.
182 will transfer at most 0x7ffff000 (2,147,479,552) bytes,
183 returning the number of bytes actually transferred.
184 .\" commit e28cc71572da38a5a12c1cfe4d7032017adccf69
185 (This is true on both 32-bit and 64-bit systems.)
189 for sending files to a TCP socket, but need
190 to send some header data in front of the file contents, you will find
191 it useful to employ the
195 to minimize the number of packets and to tune performance.
197 In Linux 2.4 and earlier,
199 could also refer to a regular file;
200 this possibility went away in the Linux 2.6.x kernel series,
201 but was restored in Linux 2.6.33.
205 system call was not designed to handle large file offsets.
206 Consequently, Linux 2.4 added
208 with a wider type for the
213 wrapper function transparently deals with the kernel differences.
215 Applications may wish to fall back to
228 refers to a socket or pipe with zero-copy support, callers must ensure the
229 transferred portions of the file referred to by
231 remain unmodified until the reader on the other end of
233 has consumed the transferred data.
237 call supports transferring data between arbitrary file descriptors
238 provided one (or both) of them is a pipe.
240 .BR copy_file_range (2),