mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-08 20:10:15 +00:00
Drag memory-mapped file handling into C++
This commit is contained in:
parent
fb9f3b6068
commit
3d56a56464
@ -2,7 +2,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "memfile.h"
|
#include "memfile.h"
|
||||||
|
}
|
||||||
|
|
||||||
#define INCREMENT 131072
|
#define INCREMENT 131072
|
||||||
|
|
||||||
@ -11,12 +14,12 @@ struct memfile *memfile_open(int fd) {
|
|||||||
return NULL;
|
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) {
|
if (map == MAP_FAILED) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct memfile *mf = malloc(sizeof(struct memfile));
|
struct memfile *mf = (struct memfile *) malloc(sizeof(struct memfile));
|
||||||
if (mf == NULL) {
|
if (mf == NULL) {
|
||||||
munmap(map, INCREMENT);
|
munmap(map, INCREMENT);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -58,7 +61,7 @@ int memfile_write(struct memfile *file, void *s, long long len) {
|
|||||||
return -1;
|
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) {
|
if (file->map == MAP_FAILED) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user