I tried using mmap to copy very large files in the following way :
I used the variables bytes instead of the filesize for mmap as I guess mapping wont work for very large files.This is working for text files but not for binary files.
if((fps = open(source, O_RDONLY)) == -1)
printf("error : can't open source file for reading\n");
if((fpd = open(dest, O_RDWR | O_CREAT | O_TRUNC, 0777)) == -1)
printf("error : cant open destination file for writing\n");
printf("\nsource = %s\n",source);
while(filesize > 0)
if(filesize < bytes)
printf("mmap error : fps\n");
if((dst=mmap((caddr_t)0,bytes,PROT_READ | PROT_WRITE,MAP_SHARED,fpd,0))==MAP_FAILED)
printf("mmap error : fpd\n");
printf("munmap error : src\n");
printf("munmap error : dst\n");
The problem with copying binary files especially video files using mmap is that the destination file is broken (as reported by VLC media player).How can I solve this??