title: sendfile64 only copy about 2GB
body: <p>I need to use sendfile64 to copy about 16GB of files. What I have achieved so far is</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/sendfile.h&gt;
  #include &lt;sys/stat.h&gt;
  
  int main (int argc, char** argv)
  {
    long long src;
    long long dest;
    struct stat64 stat_buf;
    off64_t offset = 0LL;
    long long rc;
  
    if (argc != 3) {
      fprintf(stderr, "usage: %s &lt;source&gt; &lt;destination&gt;\n", argv[0]);
      exit(1);
    }
  
    src = open64(argv[1], O_RDONLY);
    if (src == -1) {
      fprintf(stderr, "unable to open '%s': %s\n", argv[1], strerror(errno));
      exit(1);
    }
  
    fstat64(src, &amp;stat_buf);
  
    dest = open64(argv[2], O_WRONLY|O_CREAT, stat_buf.st_mode);
    if (dest == -1) {
      fprintf(stderr, "unable to open '%s': %s\n", argv[2], strerror(errno));
      exit(1);
    }
  
   /* copy file using sendfile */
   rc = sendfile64 (dest, src, &amp;offset, stat_buf.st_size);
   if (rc == -1) {
      fprintf(stderr, "error from sendfile: %s\n", strerror(errno));
      exit(1);
   }
   if (rc != stat_buf.st_size) {
     fprintf(stderr, "incomplete transfer from sendfile: %lld of %lld bytes\n",
             rc,
             (long long)stat_buf.st_size);
     exit(1);
   }
  
   /* clean up and exit */
   close(dest);
   close(src);
  
   return 0;
  }
  </code></pre>
  
  <p>I have compiled using</p>
  
  <pre><code>g++ BigCopy2.cpp -o BigCopy2 -D_FILE_OFFSET_BITS=64 -DLARGEFILE64_SOURCE
  </code></pre>
  
  <p>The problem is I still can't copy more than 2GB of file.</p>
  
  <p>Can someone point me where is my mistake? </p>