1 .\" This man page is Copyright (C) 1998 Pawel Krawczyk.
2 .\" Permission is granted to distribute possibly modified copies
3 .\" of this page provided the header is included verbatim,
4 .\" and in case of nontrivial modification author and date
5 .\" of the modification is added to the header.
6 .\" $Id: sendfile.2,v 1.5 1999/05/18 11:54:11 freitag Exp $
7 .\" 2000-11-19 bert hubert <ahu@ds9a.nl>: in_fd cannot be socket
10 .\" updated description of in_fd and out_fd for 2.6
11 .\" Various wording and formatting changes
13 .\" 2005-03-31 Martin Pool <mbp@sourcefrog.net> mmap() improvements
15 .TH SENDFILE 2 2004-12-17 "Linux Man Page" "Linux Programmer's Manual"
17 sendfile \- transfer data between file descriptors
19 .B #include <sys/sendfile.h>
21 .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
22 offset ", size_t" " count" );
23 .\" The below is too ugly. Comments about glibc versions belong
24 .\" in the notes, not in the header.
26 .\" .B #include <features.h>
28 .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2
30 .\" .B #include <sys/sendfile.h>
34 .\" .B #include <sys/types.h>
36 .\" .B /* No system prototype before glibc 2.1. */
38 .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
39 .\" offset ", size_t" " count" )
45 copies data between one file descriptor and another.
46 Because this copying is done within the kernel,
48 is more efficient than the combination of
52 which would require transferring data to and from user space.
55 should be a file descriptor opened for reading and
57 should be a descriptor opened for writing.
61 is not NULL, then it points
62 to a variable holding the file offset from which
64 will start reading data from
68 returns, this variable
69 will be set to the offset of the byte following the last byte that was read.
74 does not modify the current file offset of
76 otherwise the current file offset is adjusted to reflect
77 the number of bytes read from
81 is the number of bytes to copy between the file descriptors.
83 Presently (Linux 2.6.9):
85 must correspond to a file which supports
88 (i.e., it cannot be a socket);
91 must refer to a socket.
93 Applications may wish to fall back to
94 .BR read (2)/ write (2)
97 fails with EINVAL or ENOSYS.
101 for sending files to a TCP socket, but need
102 to send some header data in front of the file contents, you will find
103 it useful to employ the
107 to minimize the number of packets and to tune performance.
109 In Linux 2.4 and earlier,
111 could refer to a regular file, and
113 changed the current offset of that file.
115 If the transfer was successful, the number of bytes written to
117 is returned. On error, \-1 is returned, and
119 is set appropriately.
123 Non-blocking 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
141 Unspecified error while reading from
145 Insufficient memory to read from
149 is a new feature in Linux 2.2.
150 The include file <sys/sendfile.h> is present since glibc2.1.
152 Not specified in POSIX.1-2001, or other standards.
154 Other Unix systems implement
156 with different semantics and prototypes.
157 It should not be used in portable programs.