Add deflate_decompress function
Needed to implement decompressors for gzip without headers. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
bbaa8f1bb6
commit
50e8902c0e
|
@ -31,6 +31,7 @@
|
|||
#define _ZLIB_H
|
||||
|
||||
#include <linux/zconf.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
/* zlib deflate based on ZLIB_VERSION "1.1.3" */
|
||||
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
|
||||
|
@ -708,4 +709,7 @@ extern int zlib_inflateInit2(z_streamp strm, int windowBits);
|
|||
* return len or negative error code. */
|
||||
extern int zlib_inflate_blob(void *dst, unsigned dst_sz, const void *src, unsigned src_sz);
|
||||
|
||||
int deflate_decompress(struct z_stream_s *s, const u8 *src, unsigned int slen,
|
||||
u8 *dst, unsigned int *dlen);
|
||||
|
||||
#endif /* _ZLIB_H */
|
||||
|
|
|
@ -183,4 +183,43 @@ gunzip_nomem1:
|
|||
return rc; /* returns Z_OK (0) if successful */
|
||||
}
|
||||
|
||||
int deflate_decompress(struct z_stream_s *stream, const u8 *src, unsigned int slen, u8 *dst,
|
||||
unsigned int *dlen)
|
||||
{
|
||||
|
||||
int ret = 0;
|
||||
|
||||
ret = zlib_inflateReset(stream);
|
||||
if (ret != Z_OK) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
stream->next_in = (u8 *)src;
|
||||
stream->avail_in = slen;
|
||||
stream->next_out = (u8 *)dst;
|
||||
stream->avail_out = *dlen;
|
||||
|
||||
ret = zlib_inflate(stream, Z_SYNC_FLUSH);
|
||||
/*
|
||||
* Work around a bug in zlib, which sometimes wants to taste an extra
|
||||
* byte when being used in the (undocumented) raw deflate mode.
|
||||
* (From USAGI).
|
||||
*/
|
||||
if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
|
||||
u8 zerostuff = 0;
|
||||
stream->next_in = &zerostuff;
|
||||
stream->avail_in = 1;
|
||||
ret = zlib_inflate(stream, Z_FINISH);
|
||||
}
|
||||
if (ret != Z_STREAM_END) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
ret = 0;
|
||||
*dlen = stream->total_out;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define decompress gunzip
|
||||
|
|
Loading…
Reference in New Issue