========================================================================= */
| 349 | |
| 350 | /* ========================================================================= */ |
| 351 | int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, |
| 352 | uInt dictLength) |
| 353 | { |
| 354 | deflate_state *s; |
| 355 | uInt str, n; |
| 356 | int wrap; |
| 357 | unsigned avail; |
| 358 | z_const unsigned char *next; |
| 359 | |
| 360 | if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) |
| 361 | return Z_STREAM_ERROR; |
| 362 | s = strm->state; |
| 363 | wrap = s->wrap; |
| 364 | if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) |
| 365 | return Z_STREAM_ERROR; |
| 366 | |
| 367 | /* when using zlib wrappers, compute Adler-32 for provided dictionary */ |
| 368 | if (wrap == 1) |
| 369 | strm->adler = adler32(strm->adler, dictionary, dictLength); |
| 370 | s->wrap = 0; /* avoid computing Adler-32 in read_buf */ |
| 371 | |
| 372 | /* if dictionary would fill window, just replace the history */ |
| 373 | if (dictLength >= s->w_size) { |
| 374 | if (wrap == 0) { /* already empty otherwise */ |
| 375 | CLEAR_HASH(s); |
| 376 | s->strstart = 0; |
| 377 | s->block_start = 0L; |
| 378 | s->insert = 0; |
| 379 | } |
| 380 | dictionary += dictLength - s->w_size; /* use the tail */ |
| 381 | dictLength = s->w_size; |
| 382 | } |
| 383 | |
| 384 | /* insert dictionary into window and hash */ |
| 385 | avail = strm->avail_in; |
| 386 | next = strm->next_in; |
| 387 | strm->avail_in = dictLength; |
| 388 | strm->next_in = (z_const Bytef *)dictionary; |
| 389 | fill_window(s); |
| 390 | while (s->lookahead >= MIN_MATCH) { |
| 391 | str = s->strstart; |
| 392 | n = s->lookahead - (MIN_MATCH-1); |
| 393 | do { |
| 394 | UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); |
| 395 | #ifndef FASTEST |
| 396 | s->prev[str & s->w_mask] = s->head[s->ins_h]; |
| 397 | #endif |
| 398 | s->head[s->ins_h] = (Pos)str; |
| 399 | str++; |
| 400 | } while (--n); |
| 401 | s->strstart = str; |
| 402 | s->lookahead = MIN_MATCH-1; |
| 403 | fill_window(s); |
| 404 | } |
| 405 | s->strstart += s->lookahead; |
| 406 | s->block_start = (long)s->strstart; |
| 407 | s->insert = s->lookahead; |
| 408 | s->lookahead = 0; |
nothing calls this directly
no test coverage detected