]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - lib/gunzip.c
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <u-boot/zlib.h>
15 #define ZALLOC_ALIGNMENT 16
23 void *gzalloc(void *x
, unsigned items
, unsigned size
)
28 size
= (size
+ ZALLOC_ALIGNMENT
- 1) & ~(ZALLOC_ALIGNMENT
- 1);
35 void gzfree(void *x
, void *addr
, unsigned nb
)
40 int gunzip(void *dst
, int dstlen
, unsigned char *src
, unsigned long *lenp
)
47 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
48 puts ("Error: Bad gzipped data\n");
51 if ((flags
& EXTRA_FIELD
) != 0)
52 i
= 12 + src
[10] + (src
[11] << 8);
53 if ((flags
& ORIG_NAME
) != 0)
56 if ((flags
& COMMENT
) != 0)
59 if ((flags
& HEAD_CRC
) != 0)
62 puts ("Error: gunzip out of data in header\n");
66 return zunzip(dst
, dstlen
, src
, lenp
, 1, i
);
70 * Uncompress blocks compressed with zlib without headers
72 int zunzip(void *dst
, int dstlen
, unsigned char *src
, unsigned long *lenp
,
73 int stoponerr
, int offset
)
82 r
= inflateInit2(&s
, -MAX_WBITS
);
84 printf ("Error: inflateInit2() returned %d\n", r
);
87 s
.next_in
= src
+ offset
;
88 s
.avail_in
= *lenp
- offset
;
92 r
= inflate(&s
, Z_FINISH
);
93 if (stoponerr
== 1 && r
!= Z_STREAM_END
&&
94 (s
.avail_out
== 0 || r
!= Z_BUF_ERROR
)) {
95 printf("Error: inflate() returned %d\n", r
);
99 s
.avail_in
= *lenp
- offset
- (int)(s
.next_out
- (unsigned char*)dst
);
100 } while (r
== Z_BUF_ERROR
);
101 *lenp
= s
.next_out
- (unsigned char *) dst
;