- PreferredHeight is a little different than i thought.
[mono-project.git] / support / zlib_macros.c
blobdc851a7f6c2c2cac02c34dda7eaf28cf985d0a46
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 #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
19 /* Older versions of zlib do not support raw deflate or gzip */
20 return NULL;
21 #endif
23 z = malloc (sizeof (z_stream));
24 z->next_in = Z_NULL;
25 z->avail_in = 0;
26 z->next_out = Z_NULL;
27 z->avail_out = 0;
28 z->zalloc = Z_NULL;
29 z->zfree = Z_NULL;
30 z->opaque = NULL;
31 if (compress) {
32 retval = deflateInit2 (z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, gzip ? 31 : -15, 8, Z_DEFAULT_STRATEGY);
33 } else {
34 retval = inflateInit2 (z, gzip ? 31 : -15);
37 if (retval == Z_OK)
38 return z;
40 free (z);
41 return NULL;
44 void
45 free_z_stream(z_stream *z, int compress)
47 if (compress) {
48 deflateEnd (z);
49 } else {
50 inflateEnd (z);
52 free (z);
55 void
56 z_stream_set_next_in(z_stream *z, unsigned char *next_in)
58 z->next_in = next_in;
61 void
62 z_stream_set_avail_in(z_stream *z, int avail_in)
64 z->avail_in = avail_in;
67 int
68 z_stream_get_avail_in(z_stream *z)
70 return z->avail_in;
73 void
74 z_stream_set_next_out(z_stream *z, unsigned char *next_out)
76 z->next_out = next_out;
79 void
80 z_stream_set_avail_out(z_stream *z, int avail_out)
82 z->avail_out = avail_out;
85 int
86 z_stream_deflate (z_stream *z, int flush, unsigned char *next_out, int *avail_out)
88 int ret_val;
90 z->next_out = next_out;
91 z->avail_out = *avail_out;
93 ret_val = deflate (z, flush);
95 *avail_out = z->avail_out;
97 return ret_val;
101 z_stream_inflate (z_stream *z, int *avail_out)
103 int ret_val;
105 z->avail_out = *avail_out;
107 ret_val = inflate (z, Z_NO_FLUSH);
109 *avail_out = z->avail_out;
111 return ret_val;