1 #include <linux/zlib.h>
3 /* bits taken from ppc */
5 extern void *avail_ram
, *end_avail
;
12 void *zalloc(unsigned size
)
16 size
= (size
+ 7) & -8;
18 if (avail_ram
> end_avail
) {
19 //puts("oops... out of memory\n");
34 void gunzip (void *dst
, int dstlen
, unsigned char *src
, int *lenp
)
42 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
43 //puts("bad gzipped data\n");
46 if ((flags
& EXTRA_FIELD
) != 0)
47 i
= 12 + src
[10] + (src
[11] << 8);
48 if ((flags
& ORIG_NAME
) != 0)
51 if ((flags
& COMMENT
) != 0)
54 if ((flags
& HEAD_CRC
) != 0)
57 //puts("gunzip: ran out of data in header\n");
61 s
.workspace
= zalloc(zlib_inflate_workspacesize());
62 r
= zlib_inflateInit2(&s
, -MAX_WBITS
);
64 //puts("inflateInit2 returned "); puthex(r); puts("\n");
68 s
.avail_in
= *lenp
- i
;
71 r
= zlib_inflate(&s
, Z_FINISH
);
72 if (r
!= Z_OK
&& r
!= Z_STREAM_END
) {
73 //puts("inflate returned "); puthex(r); puts("\n");
76 *lenp
= s
.next_out
- (unsigned char *) dst
;