MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / updatewindow

Function updatewindow

ZLib/inflate.c:379–427  ·  view source on GitHub ↗

Update the window with the last wsize (normally 32K) bytes written before returning. If window does not exist yet, create it. This is only called when a window is already in use, or when output has been written during this inflate call, but the end of the deflate stream has not been reached yet. It is also called to create a window for dictionary data when a dictionary is loaded.

(strm, end, copy)

Source from the content-addressed store, hash-verified

377 The advantage may be dependent on the size of the processor's data caches.
378 */
379local int updatewindow(strm, end, copy)
380z_streamp strm;
381const Bytef *end;
382unsigned copy;
383{
384 struct inflate_state FAR *state;
385 unsigned dist;
386
387 state = (struct inflate_state FAR *)strm->state;
388
389 /* if it hasn't been done already, allocate space for the window */
390 if (state->window == Z_NULL) {
391 state->window = (unsigned char FAR *)
392 ZALLOC(strm, 1U << state->wbits,
393 sizeof(unsigned char));
394 if (state->window == Z_NULL) return 1;
395 }
396
397 /* if window not in use yet, initialize */
398 if (state->wsize == 0) {
399 state->wsize = 1U << state->wbits;
400 state->wnext = 0;
401 state->whave = 0;
402 }
403
404 /* copy state->wsize or less output bytes into the circular window */
405 if (copy >= state->wsize) {
406 zmemcpy(state->window, end - state->wsize, state->wsize);
407 state->wnext = 0;
408 state->whave = state->wsize;
409 }
410 else {
411 dist = state->wsize - state->wnext;
412 if (dist > copy) dist = copy;
413 zmemcpy(state->window + state->wnext, end - copy, dist);
414 copy -= dist;
415 if (copy) {
416 zmemcpy(state->window, end - copy, copy);
417 state->wnext = copy;
418 state->whave = state->wsize;
419 }
420 else {
421 state->wnext += dist;
422 if (state->wnext == state->wsize) state->wnext = 0;
423 if (state->whave < state->wsize) state->whave += dist;
424 }
425 }
426 return 0;
427}
428
429/* Macros for inflate(): */
430

Callers 1

inflate.cFile · 0.85

Calls 1

zmemcpyFunction · 0.85

Tested by

no test coverage detected