.\"
.\" 2005-03-31 Martin Pool <mbp@sourcefrog.net> mmap() improvements
.\"
-.TH SENDFILE 2 2015-05-07 "Linux" "Linux Programmer's Manual"
+.TH SENDFILE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
.SH NAME
sendfile \- transfer data between file descriptors
.SH SYNOPSIS
.B #include <sys/sendfile.h>
-.sp
+.PP
.BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \
offset ", size_t" " count" );
.\" The below is too ugly. Comments about glibc versions belong
and
.BR write (2),
which would require transferring data to and from user space.
-
+.PP
.I in_fd
should be a file descriptor opened for reading and
.I out_fd
should be a descriptor opened for writing.
-
+.PP
If
.I offset
is not NULL, then it points
.I offset
is not NULL, then
.BR sendfile ()
-does not modify the current file offset of
+does not modify the file offset of
.IR in_fd ;
-otherwise the current file offset is adjusted to reflect
+otherwise the file offset is adjusted to reflect
the number of bytes read from
.IR in_fd .
-
+.PP
If
.I offset
is NULL, then data will be read from
.IR in_fd
-starting at the current file offset,
+starting at the file offset,
and the file offset will be updated by the call.
-
+.PP
.I count
is the number of bytes to copy between the file descriptors.
-
+.PP
The
.IR in_fd
argument must correspond to a file which supports
.BR mmap (2)-like
operations
(i.e., it cannot be a socket).
-
+.PP
In Linux kernels before 2.6.33,
.I out_fd
must refer to a socket.
may write fewer bytes than requested;
the caller should be prepared to retry the call if there were unsent bytes.
See also NOTES.
-
+.PP
On error, \-1 is returned, and
.I errno
is set appropriately.
.TP
.B ESPIPE
.I offset
-is not NULL but the input file is not
-.BR seek (2)-able.
+is not NULL but the input file is not seekable.
.SH VERSIONS
.BR sendfile ()
first appeared in Linux 2.2.
is present since glibc 2.1.
.SH CONFORMING TO
Not specified in POSIX.1-2001, nor in other standards.
-
+.PP
Other UNIX systems implement
.BR sendfile ()
with different semantics and prototypes.
returning the number of bytes actually transferred.
.\" commit e28cc71572da38a5a12c1cfe4d7032017adccf69
(This is true on both 32-bit and 64-bit systems.)
-
+.PP
If you plan to use
.BR sendfile ()
for sending files to a TCP socket, but need
option, described in
.BR tcp (7),
to minimize the number of packets and to tune performance.
-
+.PP
In Linux 2.4 and earlier,
.I out_fd
could also refer to a regular file;
this possibility went away in the Linux 2.6.x kernel series,
but was restored in Linux 2.6.33.
-
+.PP
The original Linux
.BR sendfile ()
system call was not designed to handle large file offsets.
The glibc
.BR sendfile ()
wrapper function transparently deals with the kernel differences.
-
+.PP
Applications may wish to fall back to
.BR read (2)/ write (2)
in the case where
.B EINVAL
or
.BR ENOSYS .
-
+.PP
If
.I out_fd
refers to a socket or pipe with zero-copy support, callers must ensure the
remain unmodified until the reader on the other end of
.I out_fd
has consumed the transferred data.
-
+.PP
The Linux-specific
.BR splice (2)
-call supports transferring data between arbitrary files
-(e.g., a pair of sockets).
+call supports transferring data between arbitrary file descriptors
+provided one (or both) of them is a pipe.
.SH SEE ALSO
+.BR copy_file_range (2),
.BR mmap (2),
.BR open (2),
.BR socket (2),