wok-current view module-init-tools/stuff/lzlib.u @ rev 1103
Add Wormux game
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Jul 18 21:58:03 2008 +0200 (2008-07-18) |
parents | |
children | f0a84dc0a7c2 |
line source
1 --- module-init-tools-3.2/zlibsupport.c
2 +++ module-init-tools-3.2/zlibsupport.c
3 @@ -16,58 +16,33 @@
4 #include "testing.h"
6 #ifdef CONFIG_USE_ZLIB
7 -#include <zlib.h>
8 +#include <lzlib.h>
10 -void *grab_contents(gzFile *gzfd, unsigned long *size)
11 -{
12 - unsigned int max = 16384;
13 - void *buffer = malloc(max);
14 - int ret;
15 -
16 - if (!buffer)
17 - return NULL;
18 -
19 - *size = 0;
20 - while ((ret = gzread(gzfd, buffer + *size, max - *size)) > 0) {
21 - *size += ret;
22 - if (*size == max) {
23 - buffer = realloc(buffer, max *= 2);
24 - if (!buffer)
25 - return NULL;
26 - }
27 - }
28 - if (ret < 0) {
29 - free(buffer);
30 - buffer = NULL;
31 - }
32 - return buffer;
33 -}
34 -
35 void *grab_fd(int fd, unsigned long *size)
36 {
37 - gzFile gzfd;
38 + lzFile lzfd;
40 - gzfd = gzdopen(fd, "rb");
41 - if (!gzfd)
42 + lzfd = lzdopen(fd, "rb");
43 + if (!lzfd)
44 return NULL;
46 - /* gzclose(gzfd) would close fd, which would drop locks.
47 + /* lzclose(lzfd) would close fd, which would drop locks.
48 Don't blame zlib: POSIX locking semantics are so horribly
49 broken that they should be ripped out. */
50 - return grab_contents(gzfd, size);
51 + return lzgrab(lzfd, size);
52 }
54 /* gzopen handles uncompressed files transparently. */
55 void *grab_file(const char *filename, unsigned long *size)
56 {
57 - gzFile gzfd;
58 + lzFile lzfd;
59 void *buffer;
61 - gzfd = gzopen(filename, "rb");
62 - if (!gzfd)
63 + lzfd = lzopen(filename, "rb");
64 + if (!lzfd)
65 return NULL;
66 - buffer = grab_contents(gzfd, size);
67 - gzclose(gzfd);
68 + buffer = lzgrab(lzfd, size);
69 + lzclose(lzfd);
70 return buffer;
71 }
73 --- module-init-tools-3.2/configure
74 +++ module-init-tools-3.2/configure
75 @@ -1741,7 +1741,7 @@
76 #define CONFIG_USE_ZLIB 1
77 _ACEOF
79 - zlib_flags="-Wl,-Bstatic -lz -Wl,-Bdynamic"
80 + zlib_flags="-Wl,-Bdynamic -lz -llz"
81 fi
82 fi;