Drag memory-mapped file handling into C++

This commit is contained in:
Eric Fischer 2016-04-27 12:41:49 -07:00
parent fb9f3b6068
commit 3d56a56464

View File

@ -2,7 +2,10 @@
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include "memfile.h"
extern "C" {
#include "memfile.h"
}
#define INCREMENT 131072
@ -11,12 +14,12 @@ struct memfile *memfile_open(int fd) {
return NULL;
}
char *map = mmap(NULL, INCREMENT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
char *map = (char *) mmap(NULL, INCREMENT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
return NULL;
}
struct memfile *mf = malloc(sizeof(struct memfile));
struct memfile *mf = (struct memfile *) malloc(sizeof(struct memfile));
if (mf == NULL) {
munmap(map, INCREMENT);
return NULL;
@ -58,7 +61,7 @@ int memfile_write(struct memfile *file, void *s, long long len) {
return -1;
}
file->map = mmap(NULL, file->len, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0);
file->map = (char *) mmap(NULL, file->len, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0);
if (file->map == MAP_FAILED) {
return -1;
}