Debian Codegraph @

compat/zlib/contrib/blast/blast-test.c

raw
1 #include "blast.h" /* prototype for blast() */
2
3 /* Example of how to use blast() */
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #define CHUNK 16384
8
9 local unsigned inf(void *how, unsigned char **buf)
10 {
11 static unsigned char hold[CHUNK];
12
13 *buf = hold;
14 return fread(hold, 1, CHUNK, (FILE *)how);
15 }
16
17 local int outf(void *how, unsigned char *buf, unsigned len)
18 {
19 return fwrite(buf, 1, len, (FILE *)how) != len;
20 }
21
22 /* Decompress a PKWare Compression Library stream from stdin to stdout */
23 int main(void)
24 {
25 int ret;
26 unsigned left;
27
28 /* decompress to stdout */
29 left = 0;
30 ret = blast(inf, stdin, outf, stdout, &left, NULL);
31 if (ret != 0)
32 fprintf(stderr, "blast error: %d\n", ret);
33
34 /* count any leftover bytes */
35 while (getchar() != EOF)
36 left++;
37 if (left)
38 fprintf(stderr, "blast warning: %u unused bytes of input\n", left);
39
40 /* return blast() error code */
41 return ret;
42 }