public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] lib_generic: gunzip: New function zunzip
@ 2009-04-27  9:19 Ricardo Ribalda Delgado
  2009-04-27  9:19 ` [U-Boot] [PATCH 2/2] ubifs: BUG: Blocks commpressed with zlib Ricardo Ribalda Delgado
  2009-04-27  9:27 ` [U-Boot] [PATCH 1/2] lib_generic: gunzip: New function zunzip Wolfgang Denk
  0 siblings, 2 replies; 12+ messages in thread
From: Ricardo Ribalda Delgado @ 2009-04-27  9:19 UTC (permalink / raw)
  To: u-boot

Separate gunzip in

gunzip: Find the end of the header and call zunzip.
zunzip: Inflate gunzip block without header.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@uam.es>
---
 lib_generic/gunzip.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c
index 01a4031..d59a448 100644
--- a/lib_generic/gunzip.c
+++ b/lib_generic/gunzip.c
@@ -39,6 +39,8 @@
 int gunzip(void *, int, unsigned char *, unsigned long *);
 void *zalloc(void *, unsigned, unsigned);
 void zfree(void *, void *, unsigned);
+int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
+						int stoponerr, int offset);
 
 void *zalloc(void *x, unsigned items, unsigned size)
 {
@@ -59,8 +61,7 @@ void zfree(void *x, void *addr, unsigned nb)
 
 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
 {
-	z_stream s;
-	int r, i, flags;
+	int i, flags;
 
 	/* skip header */
 	i = 10;
@@ -84,6 +85,18 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
 		return (-1);
 	}
 
+	return zunzip(dst, dstlen, src, lenp, 1, i);
+}
+
+/*
+ * Uncompress blocks compressed with zlib without headers
+ */
+int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
+						int stoponerr, int offset)
+{
+	z_stream s;
+	int r;
+
 	s.zalloc = zalloc;
 	s.zfree = zfree;
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
@@ -95,14 +108,14 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
 	r = inflateInit2(&s, -MAX_WBITS);
 	if (r != Z_OK) {
 		printf ("Error: inflateInit2() returned %d\n", r);
-		return (-1);
+		return -1;
 	}
-	s.next_in = src + i;
-	s.avail_in = *lenp - i;
+	s.next_in = src + offset;
+	s.avail_in = *lenp - offset;
 	s.next_out = dst;
 	s.avail_out = dstlen;
 	r = inflate(&s, Z_FINISH);
-	if (r != Z_STREAM_END) {
+	if ((r != Z_STREAM_END) && (stoponerr==1)) {
 		printf ("Error: inflate() returned %d\n", r);
 		inflateEnd(&s);
 		return (-1);
@@ -110,5 +123,5 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
 	*lenp = s.next_out - (unsigned char *) dst;
 	inflateEnd(&s);
 
-	return (0);
+	return 0;
 }
-- 
1.6.2.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-04-27 11:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-27  9:19 [U-Boot] [PATCH 1/2] lib_generic: gunzip: New function zunzip Ricardo Ribalda Delgado
2009-04-27  9:19 ` [U-Boot] [PATCH 2/2] ubifs: BUG: Blocks commpressed with zlib Ricardo Ribalda Delgado
2009-04-27  9:27 ` [U-Boot] [PATCH 1/2] lib_generic: gunzip: New function zunzip Wolfgang Denk
2009-04-27  9:34   ` Ricardo Ribalda Delgado
2009-04-27 10:14     ` Wolfgang Denk
2009-04-27 10:17       ` Ricardo Ribalda Delgado
2009-04-27 10:43         ` Wolfgang Denk
2009-04-27 10:26     ` Wolfgang Denk
2009-04-27 10:33       ` Ricardo Ribalda Delgado
2009-04-27 10:48         ` Wolfgang Denk
2009-04-27 11:22           ` Ricardo Ribalda Delgado
2009-04-27 10:54         ` Stefan Roese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox