aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJean-Jacques Hiblot2017-09-15 12:57:29 +0200
committerTom Rini2017-10-05 21:31:04 -0400
commit376ddf9d4a21d0af4c70e97c52e5f0854fb2d696 (patch)
tree9a1e4561873e07703f0676bb36708719b4b844e9 /lib
parentd753f942ec12e6b5b2db73698aa6c55588053d3a (diff)
gzip: add a function to parse the header
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/gunzip.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/gunzip.c b/lib/gunzip.c
index 832b3064e76..adb86c75503 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -42,7 +42,7 @@ void gzfree(void *x, void *addr, unsigned nb)
free (addr);
}
-int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+int gzip_parse_header(const unsigned char *src, unsigned long len)
{
int i, flags;
@@ -63,12 +63,21 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
;
if ((flags & HEAD_CRC) != 0)
i += 2;
- if (i >= *lenp) {
+ if (i >= len) {
puts ("Error: gunzip out of data in header\n");
return (-1);
}
+ return i;
+}
+
+int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+{
+ int offset = gzip_parse_header(src, *lenp);
+
+ if (offset < 0)
+ return offset;
- return zunzip(dst, dstlen, src, lenp, 1, i);
+ return zunzip(dst, dstlen, src, lenp, 1, offset);
}
#ifdef CONFIG_CMD_UNZIP