1 /* $Id: inflate.c,v 1.7 2002/01/31 18:28:24 ukai Exp $ */
9 static char dummy_head[1 + 1] = {
11 (((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
15 main(int argc, char **argv)
19 char inbuf[BUFSIZE], outbuf[BUFSIZE];
20 int status, flush, retry = 0, len = 0;
23 f = fopen(argv[1], "rb");
25 fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
35 status = inflateInit(&s);
37 fprintf(stderr, "%s: inflateInit() %s\n", argv[0], zError(status));
41 s.next_out = (Bytef *) outbuf;
42 s.avail_out = sizeof(outbuf);
45 if (s.avail_in == 0) {
46 s.next_in = (Bytef *) inbuf;
47 len = s.avail_in = fread(inbuf, 1, sizeof(inbuf), f);
49 status = inflate(&s, flush);
50 if (status == Z_STREAM_END || status == Z_BUF_ERROR) {
51 if (sizeof(outbuf) - s.avail_out)
52 fwrite(outbuf, 1, sizeof(outbuf) - s.avail_out, stdout);
55 if (status == Z_DATA_ERROR && !retry++) {
56 status = inflateReset(&s);
58 fprintf(stderr, "%s: inflateReset() %s\n", argv[0],
62 s.next_in = (Bytef *) dummy_head;
63 s.avail_in = sizeof(dummy_head);
64 status = inflate(&s, flush);
65 s.next_in = (Bytef *) inbuf;
70 fprintf(stderr, "%s: inflate() %s\n", argv[0], zError(status));
73 if (s.avail_out == 0) {
74 fwrite(outbuf, 1, sizeof(outbuf), stdout);
75 s.next_out = (Bytef *) outbuf;
76 s.avail_out = sizeof(outbuf);