diff regexParser/fileread.cc @ 232:1a34e702776a

add fileread.cc
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 19 Jan 2016 13:16:35 +0900
parents
children 6d0a0126ddda
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regexParser/fileread.cc	Tue Jan 19 13:16:35 2016 +0900
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "sequentialSearch.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 = buff.matchBegin = st_mmap.file_mmap;
+    buff.buffend = buff.buff + st_mmap.size;
+    return buff;
+}
+