Using memory mapping in C for reading binary

Posted by user1320912 on Stack Overflow See other posts from Stack Overflow or by user1320912
Published on 2012-04-15T05:24:53Z Indexed on 2012/04/15 5:29 UTC
Read the original article Hit count: 200

Filed under:
|
|

I am trying to read data from a binary file and process it.It is a very large file so I thought I would use memory mapping. I am trying to use memory mapping so I can read the file byte by byte. I am getting a few compiler errors while doing this. I am doing this on a linux platform

#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>

int fd;
char *data;

fd = open("data.bin", O_RDONLY);
pagesize = 4000;
data = mmap((caddr_t)0, pagesize, PROT_READ, MAP_SHARED, fd,
pagesize);

The errors i get are : caddr not initialized, R_RDONLY not initialized, mmap has too few arguments.

Could someone help me out ?

© Stack Overflow or respective owner

Related posts about c

    Related posts about binaryfiles