diff options
author | Rob Kendrick <rjek@netsurf-browser.org> | 2006-10-26 23:53:16 +0000 |
---|---|---|
committer | Rob Kendrick <rjek@netsurf-browser.org> | 2006-10-26 23:53:16 +0000 |
commit | 88fec4362c92e6256aed46578e2359dfe0e99a56 (patch) | |
tree | 0a9efd2857e7a63938cefb7a244a9118118b4f3b | |
parent | 87a660d1ea54f126ffdc0b16d223bc6be0d3a31e (diff) | |
download | netsurf-88fec4362c92e6256aed46578e2359dfe0e99a56.tar.gz netsurf-88fec4362c92e6256aed46578e2359dfe0e99a56.tar.bz2 |
Make containers use mmap() where available
svn path=/trunk/netsurf/; revision=3018
-rw-r--r-- | utils/config.h | 3 | ||||
-rw-r--r-- | 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 <stdbool.h> #include <arpa/inet.h> #include "netsurf/utils/container.h" +#include "netsurf/utils/config.h" +#ifdef WITH_MMAP +#include <sys/mman.h> +#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); |