Skip to content

Commit

Permalink
Make sure memfile growth gets tested
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Oct 26, 2016
1 parent 8296190 commit 7e6aa19
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions memfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
#include "memfile.hpp"

#define INCREMENT 131072
#define INITIAL 256

struct memfile *memfile_open(int fd) {
if (ftruncate(fd, INCREMENT) != 0) {
if (ftruncate(fd, INITIAL) != 0) {
return NULL;
}

char *map = (char *) mmap(NULL, INCREMENT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
char *map = (char *) mmap(NULL, INITIAL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
return NULL;
}

struct memfile *mf = new memfile;
if (mf == NULL) {
munmap(map, INCREMENT);
munmap(map, INITIAL);
return NULL;
}

mf->fd = fd;
mf->map = map;
mf->len = INCREMENT;
mf->len = INITIAL;
mf->off = 0;
mf->tree = 0;

Expand Down

0 comments on commit 7e6aa19

Please sign in to comment.