]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib_generic/gunzip.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / lib_generic / gunzip.c
index 74f0bf9f3e1d042a93c877be418961ebfc40bb61..d2b7ad477916b4a03fbe6b6b439cc76456d6a9cb 100644 (file)
@@ -26,7 +26,7 @@
 #include <command.h>
 #include <image.h>
 #include <malloc.h>
-#include <zlib.h>
+#include <u-boot/zlib.h>
 
 #define        ZALLOC_ALIGNMENT        16
 #define HEAD_CRC               2
@@ -36,7 +36,6 @@
 #define RESERVED               0xe0
 #define DEFLATED               8
 
-int gunzip(void *, int, unsigned char *, unsigned long *);
 void *zalloc(void *, unsigned, unsigned);
 void zfree(void *, void *, unsigned);
 
@@ -59,8 +58,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 +82,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,19 +105,20 @@ 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_OK && r != Z_STREAM_END) {
+       if ((r != Z_STREAM_END) && (stoponerr==1)) {
                printf ("Error: inflate() returned %d\n", r);
+               inflateEnd(&s);
                return (-1);
        }
        *lenp = s.next_out - (unsigned char *) dst;
        inflateEnd(&s);
 
-       return (0);
+       return 0;
 }