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 2011-09-14 "Linux" "Linux Programmer's Manual"
21 sendfile \- transfer data between file descriptors
23 .B #include <sys/sendfile.h>
25 .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
26 offset ", size_t" " count" );
27 .\" The below is too ugly. Comments about glibc versions belong
28 .\" in the notes, not in the header.
30 .\" .B #include <features.h>
32 .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2
34 .\" .B #include <sys/sendfile.h>
38 .\" .B #include <sys/types.h>
40 .\" .B /* No system prototype before glibc 2.1. */
42 .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
43 .\" offset ", size_t" " count" )
49 copies data between one file descriptor and another.
50 Because this copying is done within the kernel,
52 is more efficient than the combination of
56 which would require transferring data to and from user space.
59 should be a file descriptor opened for reading and
61 should be a descriptor opened for writing.
65 is not NULL, then it points
66 to a variable holding the file offset from which
68 will start reading data from
72 returns, this variable
73 will be set to the offset of the byte following the last byte that was read.
78 does not modify the current file offset of
80 otherwise the current file offset is adjusted to reflect
81 the number of bytes read from
86 is NULL, then data will be read from
88 starting at the current file offset,
89 and the file offset will be updated by the call.
92 is the number of bytes to copy between the file descriptors.
96 argument must correspond to a file which supports
99 (i.e., it cannot be a socket).
101 In Linux kernels before 2.6.33,
103 must refer to a socket.
104 Since Linux 2.6.33 it can be any file.
105 If it is a regular file, then
107 changes the file offset appropriately.
109 If the transfer was successful, the number of bytes written to
112 On error, \-1 is returned, and
114 is set appropriately.
118 Nonblocking I/O has been selected using
120 and the write would block.
123 The input file was not opened for reading or the output file
124 was not opened for writing.
130 Descriptor is not valid or locked, or an
132 operation is not available for
136 Unspecified error while reading from
140 Insufficient memory to read from
144 is a new feature in Linux 2.2.
147 is present since glibc 2.1.
149 Not specified in POSIX.1-2001, or other standards.
151 Other UNIX systems implement
153 with different semantics and prototypes.
154 It should not be used in portable programs.
158 for sending files to a TCP socket, but need
159 to send some header data in front of the file contents, you will find
160 it useful to employ the
164 to minimize the number of packets and to tune performance.
166 In Linux 2.4 and earlier,
168 could also refer to a regular file, and
170 changed the current offset of that file.
174 system call was not designed to handle large file offsets.
175 Consequently, Linux 2.4 added
177 with a wider type for the
182 wrapper function transparently deals with the kernel differences.
184 Applications may wish to fall back to
185 .BR read (2)/ write (2)
195 call supports transferring data between arbitrary files
196 (e.g., a pair of sockets).
204 This page is part of release 3.65 of the Linux
207 A description of the project,
208 and information about reporting bugs,
210 \%http://www.kernel.org/doc/man\-pages/.