add some (mostly non-working) data binding tests
[mono-project.git] / support / zlib_macros.c
blobd022e041047a6bc6d60ffb9179b63a2278880d90
1 /*
2 * Helper routines to use Zlib
4 * Author:
5 * Christopher Lahey (clahey@ximian.co)
7 * (C) 2004 Novell, Inc.
8 */
9 #include <config.h>
10 #if defined (HAVE_ZLIB)
11 #include <zlib.h>
12 #else
13 #include "zlib.h"
14 #endif
16 #include <stdlib.h>
18 z_stream *
19 create_z_stream(int compress, unsigned char gzip)
21 z_stream *z;
22 int retval;
24 #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
25 /* Older versions of zlib do not support raw deflate or gzip */
26 return NULL;
27 #endif
29 z = malloc (sizeof (z_stream));
30 z->next_in = Z_NULL;
31 z->avail_in = 0;
32 z->next_out = Z_NULL;
33 z->avail_out = 0;
34 z->zalloc = Z_NULL;
35 z->zfree = Z_NULL;
36 z->opaque = NULL;
37 if (compress) {
38 retval = deflateInit2 (z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, gzip ? 31 : -15, 8, Z_DEFAULT_STRATEGY);
39 } else {
40 retval = inflateInit2 (z, gzip ? 31 : -15);
43 if (retval == Z_OK)
44 return z;
46 free (z);
47 return NULL;
50 void
51 free_z_stream(z_stream *z, int compress)
53 if (compress) {
54 deflateEnd (z);
55 } else {
56 inflateEnd (z);
58 free (z);
61 void
62 z_stream_set_next_in(z_stream *z, unsigned char *next_in)
64 z->next_in = next_in;
67 void
68 z_stream_set_avail_in(z_stream *z, int avail_in)
70 z->avail_in = avail_in;
73 int
74 z_stream_get_avail_in(z_stream *z)
76 return z->avail_in;
79 void
80 z_stream_set_next_out(z_stream *z, unsigned char *next_out)
82 z->next_out = next_out;
85 void
86 z_stream_set_avail_out(z_stream *z, int avail_out)
88 z->avail_out = avail_out;
91 int
92 z_stream_deflate (z_stream *z, int flush, unsigned char *next_out, int *avail_out)
94 int ret_val;
96 z->next_out = next_out;
97 z->avail_out = *avail_out;
99 ret_val = deflate (z, flush);
101 *avail_out = z->avail_out;
103 return ret_val;
107 z_stream_inflate (z_stream *z, int *avail_out)
109 int ret_val;
111 z->avail_out = *avail_out;
113 ret_val = inflate (z, Z_NO_FLUSH);
115 *avail_out = z->avail_out;
117 return ret_val;