summaryrefslogtreecommitdiff
path: root/zlib/contrib/blast/blast.c
diff options
context:
space:
mode:
authordoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-13 12:10:39 +0000
committerdoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>2017-01-13 12:10:39 +0000
commit1e5dce21ca754450ca2bb1481aed0f5ee62560b8 (patch)
tree9dc36718c039f9b387af813329eb2b4c17b149e0 /zlib/contrib/blast/blast.c
parent3c017b473af4ffc6e0ba1841ffb54bb93c9989ff (diff)
2017-01-13 Matthias Klose <doko@ubuntu.com>
* Import zlib 1.2.10. * configure: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244429 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'zlib/contrib/blast/blast.c')
-rw-r--r--zlib/contrib/blast/blast.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/zlib/contrib/blast/blast.c b/zlib/contrib/blast/blast.c
index 69ef0fe00e8d..e6e659073c63 100644
--- a/zlib/contrib/blast/blast.c
+++ b/zlib/contrib/blast/blast.c
@@ -1,7 +1,7 @@
/* blast.c
- * Copyright (C) 2003, 2012 Mark Adler
+ * Copyright (C) 2003, 2012, 2013 Mark Adler
* For conditions of distribution and use, see copyright notice in blast.h
- * version 1.2, 24 Oct 2012
+ * version 1.3, 24 Aug 2013
*
* blast.c decompresses data compressed by the PKWare Compression Library.
* This function provides functionality similar to the explode() function of
@@ -24,8 +24,12 @@
* 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data
* 1.2 24 Oct 2012 - Add note about using binary mode in stdio
* - Fix comparisons of differently signed integers
+ * 1.3 24 Aug 2013 - Return unused input from blast()
+ * - Fix test code to correctly report unused input
+ * - Enable the provision of initial input to blast()
*/
+#include <stddef.h> /* for NULL */
#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
#include "blast.h" /* prototype for blast() */
@@ -256,7 +260,7 @@ local int construct(struct huffman *h, const unsigned char *rep, int n)
* next, 0 for literals, 1 for length/distance.
*
* - If literals are uncoded, then the next eight bits are the literal, in the
- * normal bit order in th stream, i.e. no bit-reversal is needed. Similarly,
+ * normal bit order in the stream, i.e. no bit-reversal is needed. Similarly,
* no bit reversal is needed for either the length extra bits or the distance
* extra bits.
*
@@ -376,7 +380,8 @@ local int decomp(struct state *s)
}
/* See comments in blast.h */
-int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
+int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow,
+ unsigned *left, unsigned char **in)
{
struct state s; /* input/output state */
int err; /* return value */
@@ -384,7 +389,12 @@ int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
/* initialize input state */
s.infun = infun;
s.inhow = inhow;
- s.left = 0;
+ if (left != NULL && *left) {
+ s.left = *left;
+ s.in = *in;
+ }
+ else
+ s.left = 0;
s.bitbuf = 0;
s.bitcnt = 0;
@@ -400,6 +410,12 @@ int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
else
err = decomp(&s); /* decompress */
+ /* return unused input */
+ if (left != NULL)
+ *left = s.left;
+ if (in != NULL)
+ *in = s.left ? s.in : NULL;
+
/* write any leftover output and update the error code if needed */
if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
err = 1;
@@ -429,16 +445,20 @@ local int outf(void *how, unsigned char *buf, unsigned len)
/* Decompress a PKWare Compression Library stream from stdin to stdout */
int main(void)
{
- int ret, n;
+ int ret;
+ unsigned left;
/* decompress to stdout */
- ret = blast(inf, stdin, outf, stdout);
- if (ret != 0) fprintf(stderr, "blast error: %d\n", ret);
-
- /* see if there are any leftover bytes */
- n = 0;
- while (getchar() != EOF) n++;
- if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n);
+ left = 0;
+ ret = blast(inf, stdin, outf, stdout, &left, NULL);
+ if (ret != 0)
+ fprintf(stderr, "blast error: %d\n", ret);
+
+ /* count any leftover bytes */
+ while (getchar() != EOF)
+ left++;
+ if (left)
+ fprintf(stderr, "blast warning: %u unused bytes of input\n", left);
/* return blast() error code */
return ret;