#include #include #include #include int main() { int fd_in = 0; int fd_out = 0; struct stat stat_buf; off_t offset = 0; ssize_t count = 0; if ((fd_in=open("sendfile.c",O_RDONLY))<0) { perror("open"); exit(1); } if ((fd_out=open("sendfile.out",O_CREAT|O_TRUNC|O_WRONLY,S_IRWXU))<0) { perror("open"); exit(1); } if (fstat(fd_in,&stat_buf)) { perror("fstat"); } count = sendfile(fd_out,fd_in,&offset,stat_buf.st_size); if (count < 0) perror("sendfile"); if (close(fd_in) < 0) perror("close"); if (close(fd_out) < 0) perror("close"); return 0; }