1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _Z_UTIL_H
14#define _Z_UTIL_H
15
16#include <linux/zlib.h>
17#include <linux/string.h>
18#include <linux/kernel.h>
19
20typedef unsigned char uch;
21typedef unsigned short ush;
22typedef unsigned long ulg;
23
24
25
26#define STORED_BLOCK 0
27#define STATIC_TREES 1
28#define DYN_TREES 2
29
30
31#define MIN_MATCH 3
32#define MAX_MATCH 258
33
34
35#define PRESET_DICT 0x20
36
37
38
39
40
41#ifndef OS_CODE
42# define OS_CODE 0x03
43#endif
44
45
46
47typedef uLong (*check_func) (uLong check, const Byte *buf,
48 uInt len);
49
50
51
52
53#define BASE 65521L
54#define NMAX 5552
55
56
57#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
58#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
59#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
60#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
61#define DO16(buf) DO8(buf,0); DO8(buf,8);
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78static inline uLong zlib_adler32(uLong adler,
79 const Byte *buf,
80 uInt len)
81{
82 unsigned long s1 = adler & 0xffff;
83 unsigned long s2 = (adler >> 16) & 0xffff;
84 int k;
85
86 if (buf == NULL) return 1L;
87
88 while (len > 0) {
89 k = len < NMAX ? len : NMAX;
90 len -= k;
91 while (k >= 16) {
92 DO16(buf);
93 buf += 16;
94 k -= 16;
95 }
96 if (k != 0) do {
97 s1 += *buf++;
98 s2 += s1;
99 } while (--k);
100 s1 %= BASE;
101 s2 %= BASE;
102 }
103 return (s2 << 16) | s1;
104}
105
106#endif
107