1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/zlib.h>
4 /* bits taken from ppc */
6 extern void *avail_ram
, *end_avail
;
13 void *zalloc(unsigned size
)
17 size
= (size
+ 7) & -8;
19 if (avail_ram
> end_avail
) {
20 //puts("oops... out of memory\n");
35 void gunzip (void *dst
, int dstlen
, unsigned char *src
, int *lenp
)
43 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
44 //puts("bad gzipped data\n");
47 if ((flags
& EXTRA_FIELD
) != 0)
48 i
= 12 + src
[10] + (src
[11] << 8);
49 if ((flags
& ORIG_NAME
) != 0)
52 if ((flags
& COMMENT
) != 0)
55 if ((flags
& HEAD_CRC
) != 0)
58 //puts("gunzip: ran out of data in header\n");
62 s
.workspace
= zalloc(zlib_inflate_workspacesize());
63 r
= zlib_inflateInit2(&s
, -MAX_WBITS
);
65 //puts("inflateInit2 returned "); puthex(r); puts("\n");
69 s
.avail_in
= *lenp
- i
;
72 r
= zlib_inflate(&s
, Z_FINISH
);
73 if (r
!= Z_OK
&& r
!= Z_STREAM_END
) {
74 //puts("inflate returned "); puthex(r); puts("\n");
77 *lenp
= s
.next_out
- (unsigned char *) dst
;