summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-09-05 10:11:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-09-05 10:11:54 +0200
commit88e132b2a8a6b50c19d6384403326081ef791d58 (patch)
treee4480b7abe780ee7a95b8c5406c20aec8d07c39f /lib
parent6b0233be3886293f8db285ada525ad6da8b9c32f (diff)
parent551b412b16fa5e22d040cc49cd97cac1cc8029fc (diff)
downloadbarebox-88e132b2a8a6b50c19d6384403326081ef791d58.tar.gz
barebox-88e132b2a8a6b50c19d6384403326081ef791d58.tar.xz
Merge branch 'for-next/ubifs'
Diffstat (limited to 'lib')
-rw-r--r--lib/decompress_inflate.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
index 5c1ebb6850..d5ea01ad56 100644
--- a/lib/decompress_inflate.c
+++ b/lib/decompress_inflate.c
@@ -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