Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zlib_macros.c « support - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 69423f2339bd5b533a7fdc0b529d753748889241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Helper routines to use Zlib
 *
 * Author:
 *   Christopher Lahey (clahey@ximian.co)
 *
 * (C) 2004 Novell, Inc.
 */
#include <zlib.h>
#include <stdlib.h>

z_stream *
create_z_stream(int compress, unsigned char gzip)
{
	z_stream *z;
	int retval;

	z = malloc (sizeof (z_stream));
	z->next_in = Z_NULL;
	z->avail_in = 0;
	z->next_out = Z_NULL;
	z->avail_out = 0;
	z->zalloc = Z_NULL;
	z->zfree = Z_NULL;
	z->opaque = NULL;
	if (compress) {
		retval = deflateInit2 (z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, gzip ? 31 : -15, 8, Z_DEFAULT_STRATEGY);
	} else {
		retval = inflateInit2 (z, gzip ? 31 : -15);
	}

	if (retval == Z_OK)
		return z;

	free (z);
	return NULL;
}

void
free_z_stream(z_stream *z, int compress)
{
	if (compress) {
		deflateEnd (z);
	} else {
		inflateEnd (z);
	}
	free (z);
}

void
z_stream_set_next_in(z_stream *z, unsigned char *next_in)
{
	z->next_in = next_in;
}

void
z_stream_set_avail_in(z_stream *z, int avail_in)
{
	z->avail_in = avail_in;
}

int
z_stream_get_avail_in(z_stream *z)
{
	return z->avail_in;
}

void
z_stream_set_next_out(z_stream *z, unsigned char *next_out)
{
	z->next_out = next_out;
}

void
z_stream_set_avail_out(z_stream *z, int avail_out)
{
	z->avail_out = avail_out;
}

int
z_stream_deflate (z_stream *z, int flush, unsigned char *next_out, int *avail_out)
{
	int ret_val;

	z->next_out = next_out;
	z->avail_out = *avail_out;

	ret_val = deflate (z, flush);

	*avail_out = z->avail_out;

	return ret_val;
}

int
z_stream_inflate (z_stream *z, int *avail_out)
{
	int ret_val;

	z->avail_out = *avail_out;

	ret_val = inflate (z, Z_NO_FLUSH);

	*avail_out = z->avail_out;

	return ret_val;
}