MCPcopy Create free account
hub / github.com/F-Stack/f-stack / updatewindow

Function updatewindow

freebsd/contrib/zlib/inflate.c:396–444  ·  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

394 The advantage may be dependent on the size of the processor's data caches.
395 */
396local int updatewindow(strm, end, copy)
397z_streamp strm;
398const Bytef *end;
399unsigned copy;
400{
401 struct inflate_state FAR *state;
402 unsigned dist;
403
404 state = (struct inflate_state FAR *)strm->state;
405
406 /* if it hasn't been done already, allocate space for the window */
407 if (state->window == Z_NULL) {
408 state->window = (unsigned char FAR *)
409 ZALLOC(strm, 1U << state->wbits,
410 sizeof(unsigned char));
411 if (state->window == Z_NULL) return 1;
412 }
413
414 /* if window not in use yet, initialize */
415 if (state->wsize == 0) {
416 state->wsize = 1U << state->wbits;
417 state->wnext = 0;
418 state->whave = 0;
419 }
420
421 /* copy state->wsize or less output bytes into the circular window */
422 if (copy >= state->wsize) {
423 zmemcpy(state->window, end - state->wsize, state->wsize);
424 state->wnext = 0;
425 state->whave = state->wsize;
426 }
427 else {
428 dist = state->wsize - state->wnext;
429 if (dist > copy) dist = copy;
430 zmemcpy(state->window + state->wnext, end - copy, dist);
431 copy -= dist;
432 if (copy) {
433 zmemcpy(state->window, end - copy, copy);
434 state->wnext = copy;
435 state->whave = state->wsize;
436 }
437 else {
438 state->wnext += dist;
439 if (state->wnext == state->wsize) state->wnext = 0;
440 if (state->whave < state->wsize) state->whave += dist;
441 }
442 }
443 return 0;
444}
445
446/* Macros for inflate(): */
447

Callers 1

inflate.cFile · 0.85

Calls 1

zmemcpyFunction · 0.85

Tested by

no test coverage detected