Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zlib: clean up some dead code

Cleanup unused `if 0'-ed functions, which have been dead since 2006
(commits 87c2ce3b9305 ("lib/zlib*: cleanups") by Adrian Bunk and
4f3865fb57a0 ("zlib_inflate: Upgrade library code to a recent version")
by Richard Purdie):

- zlib_deflateSetDictionary
- zlib_deflateParams
- zlib_deflateCopy
- zlib_inflateSync
- zlib_syncsearch
- zlib_inflateSetDictionary
- zlib_inflatePrime

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Sergey Senozhatsky and committed by
Linus Torvalds
62e7ca52 0f9859ca

-393
-118
include/linux/zlib.h
··· 493 493 method). msg is set to null if there is no error message. deflateInit2 does 494 494 not perform any compression: this will be done by deflate(). 495 495 */ 496 - 497 - #if 0 498 - extern int zlib_deflateSetDictionary (z_streamp strm, 499 - const Byte *dictionary, 500 - uInt dictLength); 501 - #endif 502 - /* 503 - Initializes the compression dictionary from the given byte sequence 504 - without producing any compressed output. This function must be called 505 - immediately after deflateInit, deflateInit2 or deflateReset, before any 506 - call of deflate. The compressor and decompressor must use exactly the same 507 - dictionary (see inflateSetDictionary). 508 - 509 - The dictionary should consist of strings (byte sequences) that are likely 510 - to be encountered later in the data to be compressed, with the most commonly 511 - used strings preferably put towards the end of the dictionary. Using a 512 - dictionary is most useful when the data to be compressed is short and can be 513 - predicted with good accuracy; the data can then be compressed better than 514 - with the default empty dictionary. 515 - 516 - Depending on the size of the compression data structures selected by 517 - deflateInit or deflateInit2, a part of the dictionary may in effect be 518 - discarded, for example if the dictionary is larger than the window size in 519 - deflate or deflate2. Thus the strings most likely to be useful should be 520 - put at the end of the dictionary, not at the front. 521 - 522 - Upon return of this function, strm->adler is set to the Adler32 value 523 - of the dictionary; the decompressor may later use this value to determine 524 - which dictionary has been used by the compressor. (The Adler32 value 525 - applies to the whole dictionary even if only a subset of the dictionary is 526 - actually used by the compressor.) 527 - 528 - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 529 - parameter is invalid (such as NULL dictionary) or the stream state is 530 - inconsistent (for example if deflate has already been called for this stream 531 - or if the compression method is bsort). deflateSetDictionary does not 532 - perform any compression: this will be done by deflate(). 533 - */ 534 - 535 - #if 0 536 - extern int zlib_deflateCopy (z_streamp dest, z_streamp source); 537 - #endif 538 - 539 - /* 540 - Sets the destination stream as a complete copy of the source stream. 541 - 542 - This function can be useful when several compression strategies will be 543 - tried, for example when there are several ways of pre-processing the input 544 - data with a filter. The streams that will be discarded should then be freed 545 - by calling deflateEnd. Note that deflateCopy duplicates the internal 546 - compression state which can be quite large, so this strategy is slow and 547 - can consume lots of memory. 548 - 549 - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 550 - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 551 - (such as zalloc being NULL). msg is left unchanged in both source and 552 - destination. 553 - */ 554 496 555 497 extern int zlib_deflateReset (z_streamp strm); 556 498 /* ··· 509 567 { 510 568 return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11; 511 569 } 512 - 513 - #if 0 514 - extern int zlib_deflateParams (z_streamp strm, int level, int strategy); 515 - #endif 516 - /* 517 - Dynamically update the compression level and compression strategy. The 518 - interpretation of level and strategy is as in deflateInit2. This can be 519 - used to switch between compression and straight copy of the input data, or 520 - to switch to a different kind of input data requiring a different 521 - strategy. If the compression level is changed, the input available so far 522 - is compressed with the old level (and may be flushed); the new level will 523 - take effect only at the next call of deflate(). 524 - 525 - Before the call of deflateParams, the stream state must be set as for 526 - a call of deflate(), since the currently available input may have to 527 - be compressed and flushed. In particular, strm->avail_out must be non-zero. 528 - 529 - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 530 - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR 531 - if strm->avail_out was zero. 532 - */ 533 570 534 571 /* 535 572 extern int inflateInit2 (z_streamp strm, int windowBits); ··· 550 629 any decompression apart from reading the zlib header if present: this will 551 630 be done by inflate(). (So next_in and avail_in may be modified, but next_out 552 631 and avail_out are unchanged.) 553 - */ 554 - 555 - extern int zlib_inflateSetDictionary (z_streamp strm, 556 - const Byte *dictionary, 557 - uInt dictLength); 558 - /* 559 - Initializes the decompression dictionary from the given uncompressed byte 560 - sequence. This function must be called immediately after a call of inflate, 561 - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 562 - can be determined from the adler32 value returned by that call of inflate. 563 - The compressor and decompressor must use exactly the same dictionary (see 564 - deflateSetDictionary). For raw inflate, this function can be called 565 - immediately after inflateInit2() or inflateReset() and before any call of 566 - inflate() to set the dictionary. The application must insure that the 567 - dictionary that was used for compression is provided. 568 - 569 - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 570 - parameter is invalid (such as NULL dictionary) or the stream state is 571 - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 572 - expected one (incorrect adler32 value). inflateSetDictionary does not 573 - perform any decompression: this will be done by subsequent calls of 574 - inflate(). 575 - */ 576 - 577 - #if 0 578 - extern int zlib_inflateSync (z_streamp strm); 579 - #endif 580 - /* 581 - Skips invalid compressed data until a full flush point (see above the 582 - description of deflate with Z_FULL_FLUSH) can be found, or until all 583 - available input is skipped. No output is provided. 584 - 585 - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR 586 - if no more input was provided, Z_DATA_ERROR if no flush point has been found, 587 - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success 588 - case, the application may save the current current value of total_in which 589 - indicates where valid compressed data was found. In the error case, the 590 - application may repeatedly call inflateSync, providing more input each time, 591 - until success or end of the input data. 592 632 */ 593 633 594 634 extern int zlib_inflateReset (z_streamp strm);
-143
lib/zlib_deflate/deflate.c
··· 250 250 } 251 251 252 252 /* ========================================================================= */ 253 - #if 0 254 - int zlib_deflateSetDictionary( 255 - z_streamp strm, 256 - const Byte *dictionary, 257 - uInt dictLength 258 - ) 259 - { 260 - deflate_state *s; 261 - uInt length = dictLength; 262 - uInt n; 263 - IPos hash_head = 0; 264 - 265 - if (strm == NULL || strm->state == NULL || dictionary == NULL) 266 - return Z_STREAM_ERROR; 267 - 268 - s = (deflate_state *) strm->state; 269 - if (s->status != INIT_STATE) return Z_STREAM_ERROR; 270 - 271 - strm->adler = zlib_adler32(strm->adler, dictionary, dictLength); 272 - 273 - if (length < MIN_MATCH) return Z_OK; 274 - if (length > MAX_DIST(s)) { 275 - length = MAX_DIST(s); 276 - #ifndef USE_DICT_HEAD 277 - dictionary += dictLength - length; /* use the tail of the dictionary */ 278 - #endif 279 - } 280 - memcpy((char *)s->window, dictionary, length); 281 - s->strstart = length; 282 - s->block_start = (long)length; 283 - 284 - /* Insert all strings in the hash table (except for the last two bytes). 285 - * s->lookahead stays null, so s->ins_h will be recomputed at the next 286 - * call of fill_window. 287 - */ 288 - s->ins_h = s->window[0]; 289 - UPDATE_HASH(s, s->ins_h, s->window[1]); 290 - for (n = 0; n <= length - MIN_MATCH; n++) { 291 - INSERT_STRING(s, n, hash_head); 292 - } 293 - if (hash_head) hash_head = 0; /* to make compiler happy */ 294 - return Z_OK; 295 - } 296 - #endif /* 0 */ 297 - 298 - /* ========================================================================= */ 299 253 int zlib_deflateReset( 300 254 z_streamp strm 301 255 ) ··· 279 325 280 326 return Z_OK; 281 327 } 282 - 283 - /* ========================================================================= */ 284 - #if 0 285 - int zlib_deflateParams( 286 - z_streamp strm, 287 - int level, 288 - int strategy 289 - ) 290 - { 291 - deflate_state *s; 292 - compress_func func; 293 - int err = Z_OK; 294 - 295 - if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; 296 - s = (deflate_state *) strm->state; 297 - 298 - if (level == Z_DEFAULT_COMPRESSION) { 299 - level = 6; 300 - } 301 - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { 302 - return Z_STREAM_ERROR; 303 - } 304 - func = configuration_table[s->level].func; 305 - 306 - if (func != configuration_table[level].func && strm->total_in != 0) { 307 - /* Flush the last buffer: */ 308 - err = zlib_deflate(strm, Z_PARTIAL_FLUSH); 309 - } 310 - if (s->level != level) { 311 - s->level = level; 312 - s->max_lazy_match = configuration_table[level].max_lazy; 313 - s->good_match = configuration_table[level].good_length; 314 - s->nice_match = configuration_table[level].nice_length; 315 - s->max_chain_length = configuration_table[level].max_chain; 316 - } 317 - s->strategy = strategy; 318 - return err; 319 - } 320 - #endif /* 0 */ 321 328 322 329 /* ========================================================================= 323 330 * Put a short in the pending buffer. The 16-bit value is put in MSB order. ··· 482 567 483 568 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; 484 569 } 485 - 486 - /* ========================================================================= 487 - * Copy the source state to the destination state. 488 - */ 489 - #if 0 490 - int zlib_deflateCopy ( 491 - z_streamp dest, 492 - z_streamp source 493 - ) 494 - { 495 - #ifdef MAXSEG_64K 496 - return Z_STREAM_ERROR; 497 - #else 498 - deflate_state *ds; 499 - deflate_state *ss; 500 - ush *overlay; 501 - deflate_workspace *mem; 502 - 503 - 504 - if (source == NULL || dest == NULL || source->state == NULL) { 505 - return Z_STREAM_ERROR; 506 - } 507 - 508 - ss = (deflate_state *) source->state; 509 - 510 - *dest = *source; 511 - 512 - mem = (deflate_workspace *) dest->workspace; 513 - 514 - ds = &(mem->deflate_memory); 515 - 516 - dest->state = (struct internal_state *) ds; 517 - *ds = *ss; 518 - ds->strm = dest; 519 - 520 - ds->window = (Byte *) mem->window_memory; 521 - ds->prev = (Pos *) mem->prev_memory; 522 - ds->head = (Pos *) mem->head_memory; 523 - overlay = (ush *) mem->overlay_memory; 524 - ds->pending_buf = (uch *) overlay; 525 - 526 - memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); 527 - memcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); 528 - memcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); 529 - memcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); 530 - 531 - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); 532 - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); 533 - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; 534 - 535 - ds->l_desc.dyn_tree = ds->dyn_ltree; 536 - ds->d_desc.dyn_tree = ds->dyn_dtree; 537 - ds->bl_desc.dyn_tree = ds->bl_tree; 538 - 539 - return Z_OK; 540 - #endif 541 - } 542 - #endif /* 0 */ 543 570 544 571 /* =========================================================================== 545 572 * Read a new buffer from the current input stream, update the adler32
-132
lib/zlib_inflate/inflate.c
··· 45 45 return Z_OK; 46 46 } 47 47 48 - #if 0 49 - int zlib_inflatePrime(z_streamp strm, int bits, int value) 50 - { 51 - struct inflate_state *state; 52 - 53 - if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; 54 - state = (struct inflate_state *)strm->state; 55 - if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; 56 - value &= (1L << bits) - 1; 57 - state->hold += value << state->bits; 58 - state->bits += bits; 59 - return Z_OK; 60 - } 61 - #endif 62 - 63 48 int zlib_inflateInit2(z_streamp strm, int windowBits) 64 49 { 65 50 struct inflate_state *state; ··· 745 760 return Z_STREAM_ERROR; 746 761 return Z_OK; 747 762 } 748 - 749 - #if 0 750 - int zlib_inflateSetDictionary(z_streamp strm, const Byte *dictionary, 751 - uInt dictLength) 752 - { 753 - struct inflate_state *state; 754 - unsigned long id; 755 - 756 - /* check state */ 757 - if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; 758 - state = (struct inflate_state *)strm->state; 759 - if (state->wrap != 0 && state->mode != DICT) 760 - return Z_STREAM_ERROR; 761 - 762 - /* check for correct dictionary id */ 763 - if (state->mode == DICT) { 764 - id = zlib_adler32(0L, NULL, 0); 765 - id = zlib_adler32(id, dictionary, dictLength); 766 - if (id != state->check) 767 - return Z_DATA_ERROR; 768 - } 769 - 770 - /* copy dictionary to window */ 771 - zlib_updatewindow(strm, strm->avail_out); 772 - 773 - if (dictLength > state->wsize) { 774 - memcpy(state->window, dictionary + dictLength - state->wsize, 775 - state->wsize); 776 - state->whave = state->wsize; 777 - } 778 - else { 779 - memcpy(state->window + state->wsize - dictLength, dictionary, 780 - dictLength); 781 - state->whave = dictLength; 782 - } 783 - state->havedict = 1; 784 - return Z_OK; 785 - } 786 - #endif 787 - 788 - #if 0 789 - /* 790 - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found 791 - or when out of input. When called, *have is the number of pattern bytes 792 - found in order so far, in 0..3. On return *have is updated to the new 793 - state. If on return *have equals four, then the pattern was found and the 794 - return value is how many bytes were read including the last byte of the 795 - pattern. If *have is less than four, then the pattern has not been found 796 - yet and the return value is len. In the latter case, zlib_syncsearch() can be 797 - called again with more data and the *have state. *have is initialized to 798 - zero for the first call. 799 - */ 800 - static unsigned zlib_syncsearch(unsigned *have, unsigned char *buf, 801 - unsigned len) 802 - { 803 - unsigned got; 804 - unsigned next; 805 - 806 - got = *have; 807 - next = 0; 808 - while (next < len && got < 4) { 809 - if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) 810 - got++; 811 - else if (buf[next]) 812 - got = 0; 813 - else 814 - got = 4 - got; 815 - next++; 816 - } 817 - *have = got; 818 - return next; 819 - } 820 - #endif 821 - 822 - #if 0 823 - int zlib_inflateSync(z_streamp strm) 824 - { 825 - unsigned len; /* number of bytes to look at or looked at */ 826 - unsigned long in, out; /* temporary to save total_in and total_out */ 827 - unsigned char buf[4]; /* to restore bit buffer to byte string */ 828 - struct inflate_state *state; 829 - 830 - /* check parameters */ 831 - if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; 832 - state = (struct inflate_state *)strm->state; 833 - if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; 834 - 835 - /* if first time, start search in bit buffer */ 836 - if (state->mode != SYNC) { 837 - state->mode = SYNC; 838 - state->hold <<= state->bits & 7; 839 - state->bits -= state->bits & 7; 840 - len = 0; 841 - while (state->bits >= 8) { 842 - buf[len++] = (unsigned char)(state->hold); 843 - state->hold >>= 8; 844 - state->bits -= 8; 845 - } 846 - state->have = 0; 847 - zlib_syncsearch(&(state->have), buf, len); 848 - } 849 - 850 - /* search available input */ 851 - len = zlib_syncsearch(&(state->have), strm->next_in, strm->avail_in); 852 - strm->avail_in -= len; 853 - strm->next_in += len; 854 - strm->total_in += len; 855 - 856 - /* return no joy or set up to restart inflate() on a new block */ 857 - if (state->have != 4) return Z_DATA_ERROR; 858 - in = strm->total_in; out = strm->total_out; 859 - zlib_inflateReset(strm); 860 - strm->total_in = in; strm->total_out = out; 861 - state->mode = TYPE; 862 - return Z_OK; 863 - } 864 - #endif 865 763 866 764 /* 867 765 * This subroutine adds the data at next_in/avail_in to the output history