5 #include <sys/sendfile.h>
8 int copy_file(const char *src, const char *dest)
15 fd1 = open(src, O_RDONLY);
16 if (fd1 == -1) return -1;
19 fd2 = open(dest, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0666);
27 n = sendfile(fd2, fd1, &t, sb.st_size);
28 if (n != sb.st_size) {
37 /* the close can fail on NFS if out of space */
38 if (close(fd2) == -1) {
46 int main(int argc, char *argv[])
48 return copy_file(argv[1], argv[2]);