mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 12:36:51 +03:00
Make containers use mmap() where available
svn path=/trunk/netsurf/; revision=3018
This commit is contained in:
parent
87a660d1ea
commit
88fec4362c
@ -54,6 +54,9 @@
|
|||||||
#define WITH_PRINT
|
#define WITH_PRINT
|
||||||
/* Theme auto-install */
|
/* Theme auto-install */
|
||||||
#define WITH_THEME_INSTALL
|
#define WITH_THEME_INSTALL
|
||||||
|
#else
|
||||||
|
/* We're likely to have a working mmap() */
|
||||||
|
#define WITH_MMAP
|
||||||
#endif
|
#endif
|
||||||
#ifdef ncos
|
#ifdef ncos
|
||||||
/* Kiosk style browsing support */
|
/* Kiosk style browsing support */
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "netsurf/utils/container.h"
|
#include "netsurf/utils/container.h"
|
||||||
|
#include "netsurf/utils/config.h"
|
||||||
|
#ifdef WITH_MMAP
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct container_dirent {
|
struct container_dirent {
|
||||||
unsigned char filename[16];
|
unsigned char filename[16];
|
||||||
@ -120,14 +124,15 @@ static void container_process(struct container_ctx *ctx)
|
|||||||
unsigned char filename[16];
|
unsigned char filename[16];
|
||||||
u_int32_t start, len, flags1, flags2;
|
u_int32_t start, len, flags1, flags2;
|
||||||
|
|
||||||
|
#ifdef WITH_MMAP
|
||||||
|
ctx->data = mmap(NULL, ctx->header.diroffset, PROT_READ, MAP_PRIVATE,
|
||||||
|
fileno(ctx->fh), 0);
|
||||||
|
#else
|
||||||
ctx->data = malloc(ctx->header.diroffset);
|
ctx->data = malloc(ctx->header.diroffset);
|
||||||
|
|
||||||
/* TODO: Perhaps replace this with mmap() on UNIX? */
|
|
||||||
|
|
||||||
fseek(ctx->fh, 0, SEEK_SET);
|
fseek(ctx->fh, 0, SEEK_SET);
|
||||||
fread(ctx->data, ctx->header.diroffset, 1, ctx->fh);
|
fread(ctx->data, ctx->header.diroffset, 1, ctx->fh);
|
||||||
|
#endif
|
||||||
fseek(ctx->fh, ctx->header.diroffset, SEEK_SET);
|
fseek(ctx->fh, ctx->header.diroffset, SEEK_SET);
|
||||||
|
|
||||||
/* now work through the directory structure taking it apart into
|
/* now work through the directory structure taking it apart into
|
||||||
* our structure */
|
* our structure */
|
||||||
#define BEREAD(x) do { fread(&(x), 4, 1, ctx->fh);(x) = ntohl((x)); } while (0)
|
#define BEREAD(x) do { fread(&(x), 4, 1, ctx->fh);(x) = ntohl((x)); } while (0)
|
||||||
@ -291,7 +296,11 @@ void container_close(struct container_ctx *ctx)
|
|||||||
container_write_dir(ctx);
|
container_write_dir(ctx);
|
||||||
|
|
||||||
} else if (ctx->processed) {
|
} else if (ctx->processed) {
|
||||||
|
#ifdef WITH_MMAP
|
||||||
|
munmap(ctx->data, ctx->header.diroffset);
|
||||||
|
#else
|
||||||
free(ctx->data);
|
free(ctx->data);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(ctx->fh);
|
fclose(ctx->fh);
|
||||||
|
Loading…
Reference in New Issue
Block a user