Computer Science
SENDFILE(2) Linux Programmer's Manual SENDFILE(2)
NAME
sendfile - transfer data between file descriptors
SYNOPSIS
#include <unistd.h>
intsendfile(intout_fd,intin_fd,off_t*offset,size_tcount)
DESCRIPTION
This call copies data between file descriptor and another
file descriptor or socket. in_fd should be a file
descriptor opened for reading. out_fd should be a
descriptor opened for writing or a connected socket. off-
set is a pointer to variable holding the input file
pointer position from which sendfile(2) will start reading
data. After sendfile finished this variable will be set to
the offset of the byte following the last byte that was
read. count is the number of bytes to copy between file
descriptors.
NOTES
Sendfile does not modify the current file pointer of
in_fd, but does for out_fd.
If you plan to use sendfile for sending files to a TCP
socket, but need to send some header data in front of the
file contents, please refer to the TCP_CORK option in
tcp(4) to tune performance.
RETURN VALUE
If the transfer was succeeded, the number of bytes written
to out_fd is returned. On error, -1 is returned, and errno
is set appropriately.
ERRORS
EBADF Input file was not opened for reading or output
file was not opened for writing.
EINVAL Descriptor is not valid or locked.
ENOMEM Insufficient memory for reading from in_fd.
EIO Unspecified error while reading from in_fd.
VERSIONS
sendfile is a new feature in Linux 2.2.
Other Unixes often implement sendfile with different
semantics and prototypes. It should not be used in
portable programs.
SEE ALSO
socket(2), open(2)
Linux Man Page 1 Dec 1998 1
Back to the index