Add recursive scanning
[erinaco.git] / memmap.c
blob2d5f0d7038932f040909c81717f0ba173ec1e85e
1 #include <sys/mman.h>
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <unistd.h>
6 #include "memmap.h"
8 int mem_map_read (struct memory *mem, int fd)
10 struct stat sb;
11 int err;
13 err = fstat(fd, &sb);
14 if (err < 0)
15 return err;
16 /* We assume that file is not modified while we use mapping */
17 mem->data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
18 if (mem->data == MAP_FAILED) {
19 return -1;
21 mem->length = sb.st_size;
22 return 0;
25 void mem_unmap (struct memory *mem)
27 munmap(mem->data, mem->length);