1 /* Support for compressed modules. Willy Tarreau <willy@meta-x.org>
2 * did the support for modutils, Andrey Borzenkov <arvidjaar@mail.ru>
3 * ported it to module-init-tools, and I said it was too ugly to live
6 * (C) 2003 Rusty Russell, IBM Corporation.
16 #include "zlibsupport.h"
20 #ifdef CONFIG_USE_ZLIB
23 void *grab_contents(gzFile *gzfd, unsigned long *size)
25 unsigned int max = 16384;
26 void *buffer = NOFAIL(malloc(max));
30 while ((ret = gzread(gzfd, buffer + *size, max - *size)) > 0) {
33 buffer = NOFAIL(realloc(buffer, max *= 2));
43 /* gzopen handles uncompressed files transparently. */
44 void *grab_file(const char *filename, unsigned long *size)
50 gzfd = gzopen(filename, "rb");
53 fatal("Memory allocation failure in gzopen\n");
56 buffer = grab_contents(gzfd, size);
61 void release_file(void *data, unsigned long size)
65 #else /* ... !CONFIG_USE_ZLIB */
67 void *grab_fd(int fd, unsigned long *size)
77 map = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
78 if (map == MAP_FAILED)
83 void *grab_file(const char *filename, unsigned long *size)
88 fd = open(filename, O_RDONLY, 0);
91 map = grab_fd(fd, size);
96 void release_file(void *data, unsigned long size)