diff options
author | Akinori Ito <aito@eie.yz.yamagata-u.ac.jp> | 2001-11-09 04:59:17 +0000 |
---|---|---|
committer | Akinori Ito <aito@eie.yz.yamagata-u.ac.jp> | 2001-11-09 04:59:17 +0000 |
commit | 6c63633545c254dc085402e0f927a6826d1dd229 (patch) | |
tree | 0126fb5598304c713ea1276e294da9098b5df3b4 /inflate.c | |
parent | Initial revision (diff) | |
download | w3m-6c63633545c254dc085402e0f927a6826d1dd229.tar.gz w3m-6c63633545c254dc085402e0f927a6826d1dd229.zip |
Updates from 0.2.1 into 0.2.1-inu-1.5release-0-2-1-inu-1-5
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/inflate.c b/inflate.c new file mode 100644 index 0000000..f949274 --- /dev/null +++ b/inflate.c @@ -0,0 +1,56 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <zlib.h> + +#undef BUFSIZE +#define BUFSIZE 4096 + +int +main(int argc, char **argv) +{ + z_stream s; + FILE *f; + char inbuf[BUFSIZE], outbuf[BUFSIZE]; + int status, flush; + + if (argc > 1) { + f = fopen(argv[1], "rb"); + if (! f) + exit(1); + } else + f = stdin; + + s.zalloc = Z_NULL; + s.zfree = Z_NULL; + s.opaque = Z_NULL; + status = inflateInit(&s); + if (status != Z_OK) + exit(1); + s.avail_in = 0; + s.next_out = (Bytef *)outbuf; + s.avail_out = sizeof(outbuf); + flush = Z_NO_FLUSH; + while (1) { + if (s.avail_in == 0) { + s.next_in = (Bytef *)inbuf; + s.avail_in = fread(inbuf, 1, sizeof(inbuf), f); + } + status = inflate(&s, flush); + if (status == Z_STREAM_END) { + if (sizeof(outbuf) - s.avail_out) + fwrite(outbuf, 1, sizeof(outbuf) - s.avail_out, stdout); + break; + } + if (status != Z_OK) + exit(1); + if (s.avail_out == 0) { + fwrite(outbuf, 1, sizeof(outbuf), stdout); + s.next_out = (Bytef *)outbuf; + s.avail_out = sizeof(outbuf); + } + } + inflateEnd(&s); + fclose(f); + return 0; +} |