summaryrefslogtreecommitdiff
path: root/utils/container.c
diff options
context:
space:
mode:
authorRob Kendrick <rjek@netsurf-browser.org>2006-10-26 23:53:16 +0000
committerRob Kendrick <rjek@netsurf-browser.org>2006-10-26 23:53:16 +0000
commit88fec4362c92e6256aed46578e2359dfe0e99a56 (patch)
tree0a9efd2857e7a63938cefb7a244a9118118b4f3b /utils/container.c
parent87a660d1ea54f126ffdc0b16d223bc6be0d3a31e (diff)
downloadnetsurf-88fec4362c92e6256aed46578e2359dfe0e99a56.tar.gz
netsurf-88fec4362c92e6256aed46578e2359dfe0e99a56.tar.bz2
Make containers use mmap() where available
svn path=/trunk/netsurf/; revision=3018
Diffstat (limited to 'utils/container.c')
-rw-r--r--utils/container.c21
1 files changed, 15 insertions, 6 deletions
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);