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