Always assume 8-byte alignment for hash code purpouse.
[mono.git] / support / zlib_macros.c
1 /*
2  * Helper routines to use Zlib
3  *
4  * Author:
5  *   Christopher Lahey (clahey@ximian.co)
6  *
7  * (C) 2004 Novell, Inc.
8  */
9 #include <zlib.h>
10 #include <stdlib.h>
11
12 z_stream *
13 create_z_stream(int compress, unsigned char gzip)
14 {
15         z_stream *z;
16         int retval;
17
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);
30         }
31
32         if (retval == Z_OK)
33                 return z;
34
35         free (z);
36         return NULL;
37 }
38
39 void
40 free_z_stream(z_stream *z, int compress)
41 {
42         if (compress) {
43                 deflateEnd (z);
44         } else {
45                 inflateEnd (z);
46         }
47         free (z);
48 }
49
50 void
51 z_stream_set_next_in(z_stream *z, unsigned char *next_in)
52 {
53         z->next_in = next_in;
54 }
55
56 void
57 z_stream_set_avail_in(z_stream *z, int avail_in)
58 {
59         z->avail_in = avail_in;
60 }
61
62 int
63 z_stream_get_avail_in(z_stream *z)
64 {
65         return z->avail_in;
66 }
67
68 void
69 z_stream_set_next_out(z_stream *z, unsigned char *next_out)
70 {
71         z->next_out = next_out;
72 }
73
74 void
75 z_stream_set_avail_out(z_stream *z, int avail_out)
76 {
77         z->avail_out = avail_out;
78 }
79
80 int
81 z_stream_deflate (z_stream *z, int flush, unsigned char *next_out, int *avail_out)
82 {
83         int ret_val;
84
85         z->next_out = next_out;
86         z->avail_out = *avail_out;
87
88         ret_val = deflate (z, flush);
89
90         *avail_out = z->avail_out;
91
92         return ret_val;
93 }
94
95 int
96 z_stream_inflate (z_stream *z, int *avail_out)
97 {
98         int ret_val;
99
100         z->avail_out = *avail_out;
101
102         ret_val = inflate (z, Z_NO_FLUSH);
103
104         *avail_out = z->avail_out;
105
106         return ret_val;
107 }