Unix IPC: Memory Mapped Files
25 Nov 2012This snippet will show you how to open a file and map it into memory.
int fd, pagesize;
char *data;
/* open the file */
fd = open("somefile", O_RDONLY);
/* get the current page size */
pagesize = getpagesize();
/* map the 2nd page into memory */
data = mmap((caddr_t)0, pagesize, PROT_READ, MAP_SHARED, fd, pagesize);
/* start using the data pointer */