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 2021-03-22 "Linux" "Linux Programmer's Manual"
21 sendfile \- transfer data between file descriptors
24 .B #include <sys/sendfile.h>
26 .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
27 offset ", size_t" " count" );
28 .\" The below is too ugly. Comments about glibc versions belong
29 .\" in the notes, not in the header.
31 .\" .B #include <features.h>
32 .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2
33 .\" .B #include <sys/sendfile.h>
35 .\" .B #include <sys/types.h>
36 .\" .B /* No system prototype before glibc 2.1. */
37 .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
38 .\" offset ", size_t" " count" )
44 copies data between one file descriptor and another.
45 Because this copying is done within the kernel,
47 is more efficient than the combination of
51 which would require transferring data to and from user space.
54 should be a file descriptor opened for reading and
56 should be a descriptor opened for writing.
60 is not NULL, then it points
61 to a variable holding the file offset from which
63 will start reading data from
67 returns, this variable
68 will be set to the offset of the byte following the last byte that was read.
73 does not modify the file offset of
75 otherwise the file offset is adjusted to reflect
76 the number of bytes read from
81 is NULL, then data will be read from
83 starting at the file offset,
84 and the file offset will be updated by the call.
87 is the number of bytes to copy between the file descriptors.
91 argument must correspond to a file which supports
94 (i.e., it cannot be a socket).
96 In Linux kernels before 2.6.33,
98 must refer to a socket.
99 Since Linux 2.6.33 it can be any file.
100 If it is a regular file, then
102 changes the file offset appropriately.
104 If the transfer was successful, the number of bytes written to
107 Note that a successful call to
109 may write fewer bytes than requested;
110 the caller should be prepared to retry the call if there were unsent bytes.
113 On error, \-1 is returned, and
115 is set to indicate the error.
119 Nonblocking I/O has been selected using
121 and the write would block.
124 The input file was not opened for reading or the output file
125 was not opened for writing.
131 Descriptor is not valid or locked, or an
133 operation is not available for
144 This is not currently supported by
148 Unspecified error while reading from
152 Insufficient memory to read from
157 is too large, the operation would result in exceeding the maximum size of either
158 the input file or the output file.
162 is not NULL but the input file is not seekable.
165 first appeared in Linux 2.2.
168 is present since glibc 2.1.
170 Not specified in POSIX.1-2001, nor in other standards.
172 Other UNIX systems implement
174 with different semantics and prototypes.
175 It should not be used in portable programs.
178 will transfer at most 0x7ffff000 (2,147,479,552) bytes,
179 returning the number of bytes actually transferred.
180 .\" commit e28cc71572da38a5a12c1cfe4d7032017adccf69
181 (This is true on both 32-bit and 64-bit systems.)
185 for sending files to a TCP socket, but need
186 to send some header data in front of the file contents, you will find
187 it useful to employ the
191 to minimize the number of packets and to tune performance.
193 In Linux 2.4 and earlier,
195 could also refer to a regular file;
196 this possibility went away in the Linux 2.6.x kernel series,
197 but was restored in Linux 2.6.33.
201 system call was not designed to handle large file offsets.
202 Consequently, Linux 2.4 added
204 with a wider type for the
209 wrapper function transparently deals with the kernel differences.
211 Applications may wish to fall back to
212 .BR read (2)/ write (2)
222 refers to a socket or pipe with zero-copy support, callers must ensure the
223 transferred portions of the file referred to by
225 remain unmodified until the reader on the other end of
227 has consumed the transferred data.
231 call supports transferring data between arbitrary file descriptors
232 provided one (or both) of them is a pipe.
234 .BR copy_file_range (2),