You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

infutil.c 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* inflate_util.c -- data and routines common to blocks and codes
  2. * Copyright (C) 1995-2002 Mark Adler
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. #include "zutil.h"
  6. #include "infblock.h"
  7. #include "inftrees.h"
  8. #include "infcodes.h"
  9. #include "infutil.h"
  10. struct inflate_codes_state {int dummy;}; /* for buggy compilers */
  11. /* And'ing with mask[n] masks the lower n bits */
  12. uInt inflate_mask[17] = {
  13. 0x0000,
  14. 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  15. 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  16. };
  17. /* copy as much as possible from the sliding window to the output area */
  18. int inflate_flush(s, z, r)
  19. inflate_blocks_statef *s;
  20. z_streamp z;
  21. int r;
  22. {
  23. uInt n;
  24. Bytef *p;
  25. Bytef *q;
  26. /* local copies of source and destination pointers */
  27. p = z->next_out;
  28. q = s->read;
  29. /* compute number of bytes to copy as far as end of window */
  30. n = (uInt)((q <= s->write ? s->write : s->end) - q);
  31. if (n > z->avail_out) n = z->avail_out;
  32. if (n && r == Z_BUF_ERROR) r = Z_OK;
  33. /* update counters */
  34. z->avail_out -= n;
  35. z->total_out += n;
  36. /* update check information */
  37. if (s->checkfn != Z_NULL)
  38. z->adler = s->check = (*s->checkfn)(s->check, q, n);
  39. /* copy as far as end of window */
  40. zmemcpy(p, q, n);
  41. p += n;
  42. q += n;
  43. /* see if more to copy at beginning of window */
  44. if (q == s->end)
  45. {
  46. /* wrap pointers */
  47. q = s->window;
  48. if (s->write == s->end)
  49. s->write = s->window;
  50. /* compute bytes to copy */
  51. n = (uInt)(s->write - q);
  52. if (n > z->avail_out) n = z->avail_out;
  53. if (n && r == Z_BUF_ERROR) r = Z_OK;
  54. /* update counters */
  55. z->avail_out -= n;
  56. z->total_out += n;
  57. /* update check information */
  58. if (s->checkfn != Z_NULL)
  59. z->adler = s->check = (*s->checkfn)(s->check, q, n);
  60. /* copy */
  61. zmemcpy(p, q, n);
  62. p += n;
  63. q += n;
  64. }
  65. /* update pointers */
  66. z->next_out = p;
  67. s->read = q;
  68. /* done */
  69. return r;
  70. }