MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / updatewindow

Function updatewindow

extern/zlib/src/inflate.c:368–412  ·  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.

Source from the content-addressed store, hash-verified

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

Callers 1

inflate.cFile · 0.85

Calls 1

zmemcpyFunction · 0.85

Tested by

no test coverage detected