zutil.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* zutil.h -- internal interface and configuration of the compression library
  2. * Copyright (C) 1995-1998 Jean-loup Gailly.
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. /* WARNING: this file should *not* be used by applications. It is
  6. part of the implementation of the compression library and is
  7. subject to change. Applications should only use zlib.h.
  8. */
  9. /* @(#) $Id: zutil.h,v 1.1 2000/01/01 03:32:23 davem Exp $ */
  10. #ifndef _Z_UTIL_H
  11. #define _Z_UTIL_H
  12. #include <linux/zlib.h>
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. typedef unsigned char uch;
  16. typedef unsigned short ush;
  17. typedef unsigned long ulg;
  18. /* common constants */
  19. #ifndef DEF_WBITS
  20. # define DEF_WBITS MAX_WBITS
  21. #endif
  22. /* default windowBits for decompression. MAX_WBITS is for compression only */
  23. #if MAX_MEM_LEVEL >= 8
  24. # define DEF_MEM_LEVEL 8
  25. #else
  26. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  27. #endif
  28. /* default memLevel */
  29. #define STORED_BLOCK 0
  30. #define STATIC_TREES 1
  31. #define DYN_TREES 2
  32. /* The three kinds of block type */
  33. #define MIN_MATCH 3
  34. #define MAX_MATCH 258
  35. /* The minimum and maximum match lengths */
  36. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  37. /* target dependencies */
  38. /* Common defaults */
  39. #ifndef OS_CODE
  40. # define OS_CODE 0x03 /* assume Unix */
  41. #endif
  42. /* functions */
  43. typedef uLong (*check_func) (uLong check, const Byte *buf,
  44. uInt len);
  45. /* checksum functions */
  46. #define BASE 65521L /* largest prime smaller than 65536 */
  47. #define NMAX 5552
  48. /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
  49. #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
  50. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  51. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  52. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  53. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  54. /* ========================================================================= */
  55. /*
  56. Update a running Adler-32 checksum with the bytes buf[0..len-1] and
  57. return the updated checksum. If buf is NULL, this function returns
  58. the required initial value for the checksum.
  59. An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
  60. much faster. Usage example:
  61. uLong adler = adler32(0L, NULL, 0);
  62. while (read_buffer(buffer, length) != EOF) {
  63. adler = adler32(adler, buffer, length);
  64. }
  65. if (adler != original_adler) error();
  66. */
  67. static inline uLong zlib_adler32(uLong adler,
  68. const Byte *buf,
  69. uInt len)
  70. {
  71. unsigned long s1 = adler & 0xffff;
  72. unsigned long s2 = (adler >> 16) & 0xffff;
  73. int k;
  74. if (buf == NULL) return 1L;
  75. while (len > 0) {
  76. k = len < NMAX ? len : NMAX;
  77. len -= k;
  78. while (k >= 16) {
  79. DO16(buf);
  80. buf += 16;
  81. k -= 16;
  82. }
  83. if (k != 0) do {
  84. s1 += *buf++;
  85. s2 += s1;
  86. } while (--k);
  87. s1 %= BASE;
  88. s2 %= BASE;
  89. }
  90. return (s2 << 16) | s1;
  91. }
  92. #endif /* _Z_UTIL_H */