title: mmap, memcpy to copy file from A to B
body: <p>I'm trying to copy a file from A to B using MMAP and MEMCPY. The code below does exactly that but when I use CMP to compare the blocks, it says that "mem_copy.c dest differ: byte 1, line 1, and I'm not sure why.</p>
  
  <pre><code>int main(int argc, char **argv){
  
      int sfd, dfd;
      char *src, *dest;
      struct stat s;
  
      /* SOURCE */
      sfd = open("hello.c", O_RDONLY);
      fstat(sfd, &amp;s); // st_size = blocksize
  
      printf("%d\n", (int)s.st_size);
  
      src = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, sfd, 0);
  
      /* DESTINATION */
      dfd = open("dest", O_RDWR | O_CREAT, 0666);
  
      ftruncate(dfd, s.st_size;
  
      dest = mmap(NULL, s.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, dfd, 0);
  
      /* COPY */
  
      memcpy(dest, src, s.st_size);
  
      munmap(src, s.st_size);
      munmap(dest, s.st_size);
  
      close(sfd);
      close(dfd);
  
     return 0;
  }
  </code></pre>