mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-09 03:21:51 +00:00
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>
This commit is contained in:
parent
d753f942ec
commit
376ddf9d4a
2 changed files with 13 additions and 3 deletions
|
@ -609,6 +609,7 @@ ulong usec2ticks (unsigned long usec);
|
||||||
ulong ticks2usec (unsigned long ticks);
|
ulong ticks2usec (unsigned long ticks);
|
||||||
|
|
||||||
/* lib/gunzip.c */
|
/* lib/gunzip.c */
|
||||||
|
int gzip_parse_header(const unsigned char *src, unsigned long len);
|
||||||
int gunzip(void *, int, unsigned char *, unsigned long *);
|
int gunzip(void *, int, unsigned char *, unsigned long *);
|
||||||
int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
|
int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
|
||||||
int stoponerr, int offset);
|
int stoponerr, int offset);
|
||||||
|
|
15
lib/gunzip.c
15
lib/gunzip.c
|
@ -42,7 +42,7 @@ void gzfree(void *x, void *addr, unsigned nb)
|
||||||
free (addr);
|
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;
|
int i, flags;
|
||||||
|
|
||||||
|
@ -63,12 +63,21 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
||||||
;
|
;
|
||||||
if ((flags & HEAD_CRC) != 0)
|
if ((flags & HEAD_CRC) != 0)
|
||||||
i += 2;
|
i += 2;
|
||||||
if (i >= *lenp) {
|
if (i >= len) {
|
||||||
puts ("Error: gunzip out of data in header\n");
|
puts ("Error: gunzip out of data in header\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
return zunzip(dst, dstlen, src, lenp, 1, 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, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_CMD_UNZIP
|
#ifdef CONFIG_CMD_UNZIP
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue