added demo of signal/uid handling feature
[tridge/junkcode.git] / zcatraw.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <zlib.h>
4
5
6 int main(void)
7 {
8         char inbuf[1024], outbuf[1024];
9         struct z_stream_s zs;
10         int ret;
11
12         memset(&zs, 0, sizeof(zs));
13
14         zs.next_out = outbuf;
15         zs.avail_out = sizeof(outbuf);
16
17         ret = inflateInit2(&zs, -15);
18         if (ret != Z_OK) {
19                 fprintf(stderr,"inflateInit2 error %d\n", ret);
20                 goto failed;
21         }
22
23         while (1) {
24                 if (zs.avail_in == 0) {
25                         zs.avail_in = read(0, inbuf, sizeof(inbuf));
26                         zs.next_in = inbuf;
27                         if (zs.avail_in == 0) break;
28                 }
29
30                 ret = inflate(&zs, Z_SYNC_FLUSH);
31
32                 if (zs.avail_out < sizeof(outbuf)) {
33                         write(1, outbuf, sizeof(outbuf) - zs.avail_out);
34                         zs.avail_out = sizeof(outbuf);
35                         zs.next_out = outbuf;
36                 }
37
38                 if (ret == Z_STREAM_END) break;
39                 if (ret != Z_OK) {
40                         fprintf(stderr,"inflate error %d\n", ret);
41                         goto failed;
42                 }
43         }
44
45         return 0;
46
47 failed:
48         return -1;
49 }