* marshal.c: Iter usage.
[mono-project.git] / support / zlib_macros.c
blob69423f2339bd5b533a7fdc0b529d753748889241
1 /*
2 * Helper routines to use Zlib
4 * Author:
5 * Christopher Lahey (clahey@ximian.co)
7 * (C) 2004 Novell, Inc.
8 */
9 #include <zlib.h>
10 #include <stdlib.h>
12 z_stream *
13 create_z_stream(int compress, unsigned char gzip)
15 z_stream *z;
16 int retval;
18 z = malloc (sizeof (z_stream));
19 z->next_in = Z_NULL;
20 z->avail_in = 0;
21 z->next_out = Z_NULL;
22 z->avail_out = 0;
23 z->zalloc = Z_NULL;
24 z->zfree = Z_NULL;
25 z->opaque = NULL;
26 if (compress) {
27 retval = deflateInit2 (z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, gzip ? 31 : -15, 8, Z_DEFAULT_STRATEGY);
28 } else {
29 retval = inflateInit2 (z, gzip ? 31 : -15);
32 if (retval == Z_OK)
33 return z;
35 free (z);
36 return NULL;
39 void
40 free_z_stream(z_stream *z, int compress)
42 if (compress) {
43 deflateEnd (z);
44 } else {
45 inflateEnd (z);
47 free (z);
50 void
51 z_stream_set_next_in(z_stream *z, unsigned char *next_in)
53 z->next_in = next_in;
56 void
57 z_stream_set_avail_in(z_stream *z, int avail_in)
59 z->avail_in = avail_in;
62 int
63 z_stream_get_avail_in(z_stream *z)
65 return z->avail_in;
68 void
69 z_stream_set_next_out(z_stream *z, unsigned char *next_out)
71 z->next_out = next_out;
74 void
75 z_stream_set_avail_out(z_stream *z, int avail_out)
77 z->avail_out = avail_out;
80 int
81 z_stream_deflate (z_stream *z, int flush, unsigned char *next_out, int *avail_out)
83 int ret_val;
85 z->next_out = next_out;
86 z->avail_out = *avail_out;
88 ret_val = deflate (z, flush);
90 *avail_out = z->avail_out;
92 return ret_val;
95 int
96 z_stream_inflate (z_stream *z, int *avail_out)
98 int ret_val;
100 z->avail_out = *avail_out;
102 ret_val = inflate (z, Z_NO_FLUSH);
104 *avail_out = z->avail_out;
106 return ret_val;