annotate lib/zlib/inflate.c @ 483:98f0d3c19de2

Merge
author Nomad
date Tue, 26 Feb 2013 20:30:26 +0200
parents 9c0607679772
children
rev   line source
0
Ritor1
parents:
diff changeset
1 /* inflate.c -- zlib interface to inflate modules
Ritor1
parents:
diff changeset
2 * Copyright (C) 1995-1998 Mark Adler
Ritor1
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
Ritor1
parents:
diff changeset
4 */
Ritor1
parents:
diff changeset
5
Ritor1
parents:
diff changeset
6 #include "zutil.h"
Ritor1
parents:
diff changeset
7 #include "infblock.h"
Ritor1
parents:
diff changeset
8
Ritor1
parents:
diff changeset
9 struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
Ritor1
parents:
diff changeset
10
Ritor1
parents:
diff changeset
11 typedef enum {
Ritor1
parents:
diff changeset
12 METHOD, /* waiting for method byte */
Ritor1
parents:
diff changeset
13 FLAG, /* waiting for flag byte */
Ritor1
parents:
diff changeset
14 DICT4, /* four dictionary check bytes to go */
Ritor1
parents:
diff changeset
15 DICT3, /* three dictionary check bytes to go */
Ritor1
parents:
diff changeset
16 DICT2, /* two dictionary check bytes to go */
Ritor1
parents:
diff changeset
17 DICT1, /* one dictionary check byte to go */
Ritor1
parents:
diff changeset
18 DICT0, /* waiting for inflateSetDictionary */
Ritor1
parents:
diff changeset
19 BLOCKS, /* decompressing blocks */
Ritor1
parents:
diff changeset
20 CHECK4, /* four check bytes to go */
Ritor1
parents:
diff changeset
21 CHECK3, /* three check bytes to go */
Ritor1
parents:
diff changeset
22 CHECK2, /* two check bytes to go */
Ritor1
parents:
diff changeset
23 CHECK1, /* one check byte to go */
Ritor1
parents:
diff changeset
24 DONE, /* finished check, done */
Ritor1
parents:
diff changeset
25 BAD} /* got an error--stay here */
Ritor1
parents:
diff changeset
26 inflate_mode;
Ritor1
parents:
diff changeset
27
Ritor1
parents:
diff changeset
28 /* inflate private state */
Ritor1
parents:
diff changeset
29 struct internal_state {
Ritor1
parents:
diff changeset
30
Ritor1
parents:
diff changeset
31 /* mode */
Ritor1
parents:
diff changeset
32 inflate_mode mode; /* current inflate mode */
Ritor1
parents:
diff changeset
33
Ritor1
parents:
diff changeset
34 /* mode dependent information */
Ritor1
parents:
diff changeset
35 union {
Ritor1
parents:
diff changeset
36 uInt method; /* if FLAGS, method byte */
Ritor1
parents:
diff changeset
37 struct {
Ritor1
parents:
diff changeset
38 uLong was; /* computed check value */
Ritor1
parents:
diff changeset
39 uLong need; /* stream check value */
Ritor1
parents:
diff changeset
40 } check; /* if CHECK, check values to compare */
Ritor1
parents:
diff changeset
41 uInt marker; /* if BAD, inflateSync's marker bytes count */
Ritor1
parents:
diff changeset
42 } sub; /* submode */
Ritor1
parents:
diff changeset
43
Ritor1
parents:
diff changeset
44 /* mode independent information */
Ritor1
parents:
diff changeset
45 int nowrap; /* flag for no wrapper */
Ritor1
parents:
diff changeset
46 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
Ritor1
parents:
diff changeset
47 inflate_blocks_statef
Ritor1
parents:
diff changeset
48 *blocks; /* current inflate_blocks state */
Ritor1
parents:
diff changeset
49
Ritor1
parents:
diff changeset
50 };
Ritor1
parents:
diff changeset
51
Ritor1
parents:
diff changeset
52
Ritor1
parents:
diff changeset
53 int ZEXPORT inflateReset(z)
Ritor1
parents:
diff changeset
54 z_streamp z;
Ritor1
parents:
diff changeset
55 {
Ritor1
parents:
diff changeset
56 if (z == Z_NULL || z->state == Z_NULL)
Ritor1
parents:
diff changeset
57 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
58 z->total_in = z->total_out = 0;
Ritor1
parents:
diff changeset
59 z->msg = Z_NULL;
Ritor1
parents:
diff changeset
60 z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
Ritor1
parents:
diff changeset
61 inflate_blocks_reset(z->state->blocks, z, Z_NULL);
Ritor1
parents:
diff changeset
62 Tracev((stderr, "inflate: reset\n"));
Ritor1
parents:
diff changeset
63 return Z_OK;
Ritor1
parents:
diff changeset
64 }
Ritor1
parents:
diff changeset
65
Ritor1
parents:
diff changeset
66
Ritor1
parents:
diff changeset
67 int ZEXPORT inflateEnd(z)
Ritor1
parents:
diff changeset
68 z_streamp z;
Ritor1
parents:
diff changeset
69 {
Ritor1
parents:
diff changeset
70 if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
Ritor1
parents:
diff changeset
71 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
72 if (z->state->blocks != Z_NULL)
Ritor1
parents:
diff changeset
73 inflate_blocks_free(z->state->blocks, z);
Ritor1
parents:
diff changeset
74 ZFREE(z, z->state);
Ritor1
parents:
diff changeset
75 z->state = Z_NULL;
Ritor1
parents:
diff changeset
76 Tracev((stderr, "inflate: end\n"));
Ritor1
parents:
diff changeset
77 return Z_OK;
Ritor1
parents:
diff changeset
78 }
Ritor1
parents:
diff changeset
79
Ritor1
parents:
diff changeset
80
Ritor1
parents:
diff changeset
81 int ZEXPORT inflateInit2_(z, w, version, stream_size)
Ritor1
parents:
diff changeset
82 z_streamp z;
Ritor1
parents:
diff changeset
83 int w;
Ritor1
parents:
diff changeset
84 const char *version;
Ritor1
parents:
diff changeset
85 int stream_size;
Ritor1
parents:
diff changeset
86 {
Ritor1
parents:
diff changeset
87 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
Ritor1
parents:
diff changeset
88 stream_size != sizeof(z_stream))
Ritor1
parents:
diff changeset
89 return Z_VERSION_ERROR;
Ritor1
parents:
diff changeset
90
Ritor1
parents:
diff changeset
91 /* initialize state */
Ritor1
parents:
diff changeset
92 if (z == Z_NULL)
Ritor1
parents:
diff changeset
93 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
94 z->msg = Z_NULL;
Ritor1
parents:
diff changeset
95 if (z->zalloc == Z_NULL)
Ritor1
parents:
diff changeset
96 {
Ritor1
parents:
diff changeset
97 z->zalloc = zcalloc;
Ritor1
parents:
diff changeset
98 z->opaque = (voidpf)0;
Ritor1
parents:
diff changeset
99 }
Ritor1
parents:
diff changeset
100 if (z->zfree == Z_NULL) z->zfree = zcfree;
Ritor1
parents:
diff changeset
101 if ((z->state = (struct internal_state FAR *)
Ritor1
parents:
diff changeset
102 ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
Ritor1
parents:
diff changeset
103 return Z_MEM_ERROR;
Ritor1
parents:
diff changeset
104 z->state->blocks = Z_NULL;
Ritor1
parents:
diff changeset
105
Ritor1
parents:
diff changeset
106 /* handle undocumented nowrap option (no zlib header or check) */
Ritor1
parents:
diff changeset
107 z->state->nowrap = 0;
Ritor1
parents:
diff changeset
108 if (w < 0)
Ritor1
parents:
diff changeset
109 {
Ritor1
parents:
diff changeset
110 w = - w;
Ritor1
parents:
diff changeset
111 z->state->nowrap = 1;
Ritor1
parents:
diff changeset
112 }
Ritor1
parents:
diff changeset
113
Ritor1
parents:
diff changeset
114 /* set window size */
Ritor1
parents:
diff changeset
115 if (w < 8 || w > 15)
Ritor1
parents:
diff changeset
116 {
Ritor1
parents:
diff changeset
117 inflateEnd(z);
Ritor1
parents:
diff changeset
118 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
119 }
Ritor1
parents:
diff changeset
120 z->state->wbits = (uInt)w;
Ritor1
parents:
diff changeset
121
Ritor1
parents:
diff changeset
122 /* create inflate_blocks state */
Ritor1
parents:
diff changeset
123 if ((z->state->blocks =
Ritor1
parents:
diff changeset
124 inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
Ritor1
parents:
diff changeset
125 == Z_NULL)
Ritor1
parents:
diff changeset
126 {
Ritor1
parents:
diff changeset
127 inflateEnd(z);
Ritor1
parents:
diff changeset
128 return Z_MEM_ERROR;
Ritor1
parents:
diff changeset
129 }
Ritor1
parents:
diff changeset
130 Tracev((stderr, "inflate: allocated\n"));
Ritor1
parents:
diff changeset
131
Ritor1
parents:
diff changeset
132 /* reset state */
Ritor1
parents:
diff changeset
133 inflateReset(z);
Ritor1
parents:
diff changeset
134 return Z_OK;
Ritor1
parents:
diff changeset
135 }
Ritor1
parents:
diff changeset
136
Ritor1
parents:
diff changeset
137
Ritor1
parents:
diff changeset
138 int ZEXPORT inflateInit_(z, version, stream_size)
Ritor1
parents:
diff changeset
139 z_streamp z;
Ritor1
parents:
diff changeset
140 const char *version;
Ritor1
parents:
diff changeset
141 int stream_size;
Ritor1
parents:
diff changeset
142 {
Ritor1
parents:
diff changeset
143 return inflateInit2_(z, DEF_WBITS, version, stream_size);
Ritor1
parents:
diff changeset
144 }
Ritor1
parents:
diff changeset
145
Ritor1
parents:
diff changeset
146
Ritor1
parents:
diff changeset
147 #define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
Ritor1
parents:
diff changeset
148 #define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
Ritor1
parents:
diff changeset
149
Ritor1
parents:
diff changeset
150 int ZEXPORT inflate(z, f)
Ritor1
parents:
diff changeset
151 z_streamp z;
Ritor1
parents:
diff changeset
152 int f;
Ritor1
parents:
diff changeset
153 {
Ritor1
parents:
diff changeset
154 int r;
Ritor1
parents:
diff changeset
155 uInt b;
Ritor1
parents:
diff changeset
156
Ritor1
parents:
diff changeset
157 if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
Ritor1
parents:
diff changeset
158 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
159 f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
Ritor1
parents:
diff changeset
160 r = Z_BUF_ERROR;
Ritor1
parents:
diff changeset
161 while (1) switch (z->state->mode)
Ritor1
parents:
diff changeset
162 {
Ritor1
parents:
diff changeset
163 case METHOD:
Ritor1
parents:
diff changeset
164 NEEDBYTE
Ritor1
parents:
diff changeset
165 if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
Ritor1
parents:
diff changeset
166 {
Ritor1
parents:
diff changeset
167 z->state->mode = BAD;
Ritor1
parents:
diff changeset
168 z->msg = (char*)"unknown compression method";
Ritor1
parents:
diff changeset
169 z->state->sub.marker = 5; /* can't try inflateSync */
Ritor1
parents:
diff changeset
170 break;
Ritor1
parents:
diff changeset
171 }
Ritor1
parents:
diff changeset
172 if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
Ritor1
parents:
diff changeset
173 {
Ritor1
parents:
diff changeset
174 z->state->mode = BAD;
Ritor1
parents:
diff changeset
175 z->msg = (char*)"invalid window size";
Ritor1
parents:
diff changeset
176 z->state->sub.marker = 5; /* can't try inflateSync */
Ritor1
parents:
diff changeset
177 break;
Ritor1
parents:
diff changeset
178 }
Ritor1
parents:
diff changeset
179 z->state->mode = FLAG;
Ritor1
parents:
diff changeset
180 case FLAG:
Ritor1
parents:
diff changeset
181 NEEDBYTE
Ritor1
parents:
diff changeset
182 b = NEXTBYTE;
Ritor1
parents:
diff changeset
183 if (((z->state->sub.method << 8) + b) % 31)
Ritor1
parents:
diff changeset
184 {
Ritor1
parents:
diff changeset
185 z->state->mode = BAD;
Ritor1
parents:
diff changeset
186 z->msg = (char*)"incorrect header check";
Ritor1
parents:
diff changeset
187 z->state->sub.marker = 5; /* can't try inflateSync */
Ritor1
parents:
diff changeset
188 break;
Ritor1
parents:
diff changeset
189 }
Ritor1
parents:
diff changeset
190 Tracev((stderr, "inflate: zlib header ok\n"));
Ritor1
parents:
diff changeset
191 if (!(b & PRESET_DICT))
Ritor1
parents:
diff changeset
192 {
Ritor1
parents:
diff changeset
193 z->state->mode = BLOCKS;
Ritor1
parents:
diff changeset
194 break;
Ritor1
parents:
diff changeset
195 }
Ritor1
parents:
diff changeset
196 z->state->mode = DICT4;
Ritor1
parents:
diff changeset
197 case DICT4:
Ritor1
parents:
diff changeset
198 NEEDBYTE
Ritor1
parents:
diff changeset
199 z->state->sub.check.need = (uLong)NEXTBYTE << 24;
Ritor1
parents:
diff changeset
200 z->state->mode = DICT3;
Ritor1
parents:
diff changeset
201 case DICT3:
Ritor1
parents:
diff changeset
202 NEEDBYTE
Ritor1
parents:
diff changeset
203 z->state->sub.check.need += (uLong)NEXTBYTE << 16;
Ritor1
parents:
diff changeset
204 z->state->mode = DICT2;
Ritor1
parents:
diff changeset
205 case DICT2:
Ritor1
parents:
diff changeset
206 NEEDBYTE
Ritor1
parents:
diff changeset
207 z->state->sub.check.need += (uLong)NEXTBYTE << 8;
Ritor1
parents:
diff changeset
208 z->state->mode = DICT1;
Ritor1
parents:
diff changeset
209 case DICT1:
Ritor1
parents:
diff changeset
210 NEEDBYTE
Ritor1
parents:
diff changeset
211 z->state->sub.check.need += (uLong)NEXTBYTE;
Ritor1
parents:
diff changeset
212 z->adler = z->state->sub.check.need;
Ritor1
parents:
diff changeset
213 z->state->mode = DICT0;
Ritor1
parents:
diff changeset
214 return Z_NEED_DICT;
Ritor1
parents:
diff changeset
215 case DICT0:
Ritor1
parents:
diff changeset
216 z->state->mode = BAD;
Ritor1
parents:
diff changeset
217 z->msg = (char*)"need dictionary";
Ritor1
parents:
diff changeset
218 z->state->sub.marker = 0; /* can try inflateSync */
Ritor1
parents:
diff changeset
219 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
220 case BLOCKS:
Ritor1
parents:
diff changeset
221 r = inflate_blocks(z->state->blocks, z, r);
Ritor1
parents:
diff changeset
222 if (r == Z_DATA_ERROR)
Ritor1
parents:
diff changeset
223 {
Ritor1
parents:
diff changeset
224 z->state->mode = BAD;
Ritor1
parents:
diff changeset
225 z->state->sub.marker = 0; /* can try inflateSync */
Ritor1
parents:
diff changeset
226 break;
Ritor1
parents:
diff changeset
227 }
Ritor1
parents:
diff changeset
228 if (r == Z_OK)
Ritor1
parents:
diff changeset
229 r = f;
Ritor1
parents:
diff changeset
230 if (r != Z_STREAM_END)
Ritor1
parents:
diff changeset
231 return r;
Ritor1
parents:
diff changeset
232 r = f;
Ritor1
parents:
diff changeset
233 inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
Ritor1
parents:
diff changeset
234 if (z->state->nowrap)
Ritor1
parents:
diff changeset
235 {
Ritor1
parents:
diff changeset
236 z->state->mode = DONE;
Ritor1
parents:
diff changeset
237 break;
Ritor1
parents:
diff changeset
238 }
Ritor1
parents:
diff changeset
239 z->state->mode = CHECK4;
Ritor1
parents:
diff changeset
240 case CHECK4:
Ritor1
parents:
diff changeset
241 NEEDBYTE
Ritor1
parents:
diff changeset
242 z->state->sub.check.need = (uLong)NEXTBYTE << 24;
Ritor1
parents:
diff changeset
243 z->state->mode = CHECK3;
Ritor1
parents:
diff changeset
244 case CHECK3:
Ritor1
parents:
diff changeset
245 NEEDBYTE
Ritor1
parents:
diff changeset
246 z->state->sub.check.need += (uLong)NEXTBYTE << 16;
Ritor1
parents:
diff changeset
247 z->state->mode = CHECK2;
Ritor1
parents:
diff changeset
248 case CHECK2:
Ritor1
parents:
diff changeset
249 NEEDBYTE
Ritor1
parents:
diff changeset
250 z->state->sub.check.need += (uLong)NEXTBYTE << 8;
Ritor1
parents:
diff changeset
251 z->state->mode = CHECK1;
Ritor1
parents:
diff changeset
252 case CHECK1:
Ritor1
parents:
diff changeset
253 NEEDBYTE
Ritor1
parents:
diff changeset
254 z->state->sub.check.need += (uLong)NEXTBYTE;
Ritor1
parents:
diff changeset
255
Ritor1
parents:
diff changeset
256 if (z->state->sub.check.was != z->state->sub.check.need)
Ritor1
parents:
diff changeset
257 {
Ritor1
parents:
diff changeset
258 z->state->mode = BAD;
Ritor1
parents:
diff changeset
259 z->msg = (char*)"incorrect data check";
Ritor1
parents:
diff changeset
260 z->state->sub.marker = 5; /* can't try inflateSync */
Ritor1
parents:
diff changeset
261 break;
Ritor1
parents:
diff changeset
262 }
Ritor1
parents:
diff changeset
263 Tracev((stderr, "inflate: zlib check ok\n"));
Ritor1
parents:
diff changeset
264 z->state->mode = DONE;
Ritor1
parents:
diff changeset
265 case DONE:
Ritor1
parents:
diff changeset
266 return Z_STREAM_END;
Ritor1
parents:
diff changeset
267 case BAD:
Ritor1
parents:
diff changeset
268 return Z_DATA_ERROR;
Ritor1
parents:
diff changeset
269 default:
Ritor1
parents:
diff changeset
270 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
271 }
Ritor1
parents:
diff changeset
272 #ifdef NEED_DUMMY_RETURN
Ritor1
parents:
diff changeset
273 return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
Ritor1
parents:
diff changeset
274 #endif
Ritor1
parents:
diff changeset
275 }
Ritor1
parents:
diff changeset
276
Ritor1
parents:
diff changeset
277
Ritor1
parents:
diff changeset
278 int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
Ritor1
parents:
diff changeset
279 z_streamp z;
Ritor1
parents:
diff changeset
280 const Bytef *dictionary;
Ritor1
parents:
diff changeset
281 uInt dictLength;
Ritor1
parents:
diff changeset
282 {
Ritor1
parents:
diff changeset
283 uInt length = dictLength;
Ritor1
parents:
diff changeset
284
Ritor1
parents:
diff changeset
285 if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
Ritor1
parents:
diff changeset
286 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
287
Ritor1
parents:
diff changeset
288 if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
Ritor1
parents:
diff changeset
289 z->adler = 1L;
Ritor1
parents:
diff changeset
290
Ritor1
parents:
diff changeset
291 if (length >= ((uInt)1<<z->state->wbits))
Ritor1
parents:
diff changeset
292 {
Ritor1
parents:
diff changeset
293 length = (1<<z->state->wbits)-1;
Ritor1
parents:
diff changeset
294 dictionary += dictLength - length;
Ritor1
parents:
diff changeset
295 }
Ritor1
parents:
diff changeset
296 inflate_set_dictionary(z->state->blocks, dictionary, length);
Ritor1
parents:
diff changeset
297 z->state->mode = BLOCKS;
Ritor1
parents:
diff changeset
298 return Z_OK;
Ritor1
parents:
diff changeset
299 }
Ritor1
parents:
diff changeset
300
Ritor1
parents:
diff changeset
301
Ritor1
parents:
diff changeset
302 int ZEXPORT inflateSync(z)
Ritor1
parents:
diff changeset
303 z_streamp z;
Ritor1
parents:
diff changeset
304 {
Ritor1
parents:
diff changeset
305 uInt n; /* number of bytes to look at */
Ritor1
parents:
diff changeset
306 Bytef *p; /* pointer to bytes */
Ritor1
parents:
diff changeset
307 uInt m; /* number of marker bytes found in a row */
Ritor1
parents:
diff changeset
308 uLong r, w; /* temporaries to save total_in and total_out */
Ritor1
parents:
diff changeset
309
Ritor1
parents:
diff changeset
310 /* set up */
Ritor1
parents:
diff changeset
311 if (z == Z_NULL || z->state == Z_NULL)
Ritor1
parents:
diff changeset
312 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
313 if (z->state->mode != BAD)
Ritor1
parents:
diff changeset
314 {
Ritor1
parents:
diff changeset
315 z->state->mode = BAD;
Ritor1
parents:
diff changeset
316 z->state->sub.marker = 0;
Ritor1
parents:
diff changeset
317 }
Ritor1
parents:
diff changeset
318 if ((n = z->avail_in) == 0)
Ritor1
parents:
diff changeset
319 return Z_BUF_ERROR;
Ritor1
parents:
diff changeset
320 p = z->next_in;
Ritor1
parents:
diff changeset
321 m = z->state->sub.marker;
Ritor1
parents:
diff changeset
322
Ritor1
parents:
diff changeset
323 /* search */
Ritor1
parents:
diff changeset
324 while (n && m < 4)
Ritor1
parents:
diff changeset
325 {
Ritor1
parents:
diff changeset
326 static const Byte mark[4] = {0, 0, 0xff, 0xff};
Ritor1
parents:
diff changeset
327 if (*p == mark[m])
Ritor1
parents:
diff changeset
328 m++;
Ritor1
parents:
diff changeset
329 else if (*p)
Ritor1
parents:
diff changeset
330 m = 0;
Ritor1
parents:
diff changeset
331 else
Ritor1
parents:
diff changeset
332 m = 4 - m;
Ritor1
parents:
diff changeset
333 p++, n--;
Ritor1
parents:
diff changeset
334 }
Ritor1
parents:
diff changeset
335
Ritor1
parents:
diff changeset
336 /* restore */
Ritor1
parents:
diff changeset
337 z->total_in += p - z->next_in;
Ritor1
parents:
diff changeset
338 z->next_in = p;
Ritor1
parents:
diff changeset
339 z->avail_in = n;
Ritor1
parents:
diff changeset
340 z->state->sub.marker = m;
Ritor1
parents:
diff changeset
341
Ritor1
parents:
diff changeset
342 /* return no joy or set up to restart on a new block */
Ritor1
parents:
diff changeset
343 if (m != 4)
Ritor1
parents:
diff changeset
344 return Z_DATA_ERROR;
Ritor1
parents:
diff changeset
345 r = z->total_in; w = z->total_out;
Ritor1
parents:
diff changeset
346 inflateReset(z);
Ritor1
parents:
diff changeset
347 z->total_in = r; z->total_out = w;
Ritor1
parents:
diff changeset
348 z->state->mode = BLOCKS;
Ritor1
parents:
diff changeset
349 return Z_OK;
Ritor1
parents:
diff changeset
350 }
Ritor1
parents:
diff changeset
351
Ritor1
parents:
diff changeset
352
Ritor1
parents:
diff changeset
353 /* Returns true if inflate is currently at the end of a block generated
Ritor1
parents:
diff changeset
354 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
Ritor1
parents:
diff changeset
355 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
Ritor1
parents:
diff changeset
356 * but removes the length bytes of the resulting empty stored block. When
Ritor1
parents:
diff changeset
357 * decompressing, PPP checks that at the end of input packet, inflate is
Ritor1
parents:
diff changeset
358 * waiting for these length bytes.
Ritor1
parents:
diff changeset
359 */
Ritor1
parents:
diff changeset
360 int ZEXPORT inflateSyncPoint(z)
Ritor1
parents:
diff changeset
361 z_streamp z;
Ritor1
parents:
diff changeset
362 {
Ritor1
parents:
diff changeset
363 if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
Ritor1
parents:
diff changeset
364 return Z_STREAM_ERROR;
Ritor1
parents:
diff changeset
365 return inflate_blocks_sync_point(z->state->blocks);
Ritor1
parents:
diff changeset
366 }