#include #include #include #include #include #include #include int main (int argc, char *argv[]) { int in, out; struct stat st; off_t off = 0; ssize_t rc; in = open("test.data", O_RDONLY); if (in < 0) { perror("test.data read"); return 1; } fstat(in, &st); out = open("test.data", O_WRONLY); if (out < 0) { perror("test.data write"); return 1; } rc = sendfile(out, in, &off, st.st_size); if (rc < 0) { perror("sendfile"); close(in); unlink("out"); close(out); return 1; } close(in); close(out); return 0; }