From 88fec4362c92e6256aed46578e2359dfe0e99a56 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Thu, 26 Oct 2006 23:53:16 +0000 Subject: [PATCH] Make containers use mmap() where available svn path=/trunk/netsurf/; revision=3018 --- utils/config.h | 3 +++ utils/container.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/utils/config.h b/utils/config.h index a54f56885..459336e88 100644 --- a/utils/config.h +++ b/utils/config.h @@ -54,6 +54,9 @@ #define WITH_PRINT /* Theme auto-install */ #define WITH_THEME_INSTALL +#else + /* We're likely to have a working mmap() */ + #define WITH_MMAP #endif #ifdef ncos /* Kiosk style browsing support */ diff --git a/utils/container.c b/utils/container.c index 7bca065fe..8d02da752 100644 --- a/utils/container.c +++ b/utils/container.c @@ -21,6 +21,10 @@ #include #include #include "netsurf/utils/container.h" +#include "netsurf/utils/config.h" +#ifdef WITH_MMAP +#include +#endif struct container_dirent { unsigned char filename[16]; @@ -119,15 +123,16 @@ static void container_process(struct container_ctx *ctx) { unsigned char filename[16]; u_int32_t start, len, flags1, flags2; - - ctx->data = malloc(ctx->header.diroffset); - - /* TODO: Perhaps replace this with mmap() on UNIX? */ - + +#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); fseek(ctx->fh, 0, SEEK_SET); fread(ctx->data, ctx->header.diroffset, 1, ctx->fh); +#endif fseek(ctx->fh, ctx->header.diroffset, SEEK_SET); - /* now work through the directory structure taking it apart into * our structure */ #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); } else if (ctx->processed) { +#ifdef WITH_MMAP + munmap(ctx->data, ctx->header.diroffset); +#else free(ctx->data); +#endif } fclose(ctx->fh);