Mercurial > hg > Applications > Grep
view regexParser/fileread.cc @ 320:da02a7258d54
fix
author | mir3636 |
---|---|
date | Sun, 08 May 2016 23:31:14 +0900 |
parents | 948428caf616 |
children |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/mman.h> #include "fileread.h" st_mmap_t createSt_mmap(char* filename,int &fd) { st_mmap_t st_mmap; int map = MAP_PRIVATE; struct stat sb; if ((fd=open(filename,O_RDONLY,0666))==0) { perror(""); fprintf(stderr,"can't open %s\n",filename); } if (fstat(fd,&sb)) { perror(""); fprintf(stderr,"can't fstat %s\n",filename); } st_mmap.size = sb.st_size; unsigned char *file_mmap = (unsigned char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); if (file_mmap == NULL) { perror(""); fprintf(stderr,"cannot mmap %s\n",filename); } st_mmap.file_mmap = file_mmap; return st_mmap; } Buffer createBuffer(st_mmap_t st_mmap) { Buffer buff; buff.buff = buff.buffptr = st_mmap.file_mmap; buff.buffend = buff.buff + st_mmap.size; return buff; }