Back to home page

OSCL-LXR

 
 

    


0001 /* zutil.h -- internal interface and configuration of the compression library
0002  * Copyright (C) 1995-1998 Jean-loup Gailly.
0003  * For conditions of distribution and use, see copyright notice in zlib.h
0004  */
0005 
0006 /* WARNING: this file should *not* be used by applications. It is
0007    part of the implementation of the compression library and is
0008    subject to change. Applications should only use zlib.h.
0009  */
0010 
0011 /* @(#) $Id: zutil.h,v 1.1 2000/01/01 03:32:23 davem Exp $ */
0012 
0013 #ifndef _Z_UTIL_H
0014 #define _Z_UTIL_H
0015 
0016 #include <linux/zlib.h>
0017 #include <linux/string.h>
0018 #include <linux/kernel.h>
0019 
0020 typedef unsigned char  uch;
0021 typedef unsigned short ush;
0022 typedef unsigned long  ulg;
0023 
0024         /* common constants */
0025 
0026 #define STORED_BLOCK 0
0027 #define STATIC_TREES 1
0028 #define DYN_TREES    2
0029 /* The three kinds of block type */
0030 
0031 #define MIN_MATCH  3
0032 #define MAX_MATCH  258
0033 /* The minimum and maximum match lengths */
0034 
0035 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
0036 
0037         /* target dependencies */
0038 
0039         /* Common defaults */
0040 
0041 #ifndef OS_CODE
0042 #  define OS_CODE  0x03  /* assume Unix */
0043 #endif
0044 
0045          /* functions */
0046 
0047 typedef uLong (*check_func) (uLong check, const Byte *buf,
0048                        uInt len);
0049 
0050 
0051                         /* checksum functions */
0052 
0053 #define BASE 65521L /* largest prime smaller than 65536 */
0054 #define NMAX 5552
0055 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
0056 
0057 #define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
0058 #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
0059 #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
0060 #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
0061 #define DO16(buf)   DO8(buf,0); DO8(buf,8);
0062 
0063 /* ========================================================================= */
0064 /*
0065      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
0066    return the updated checksum. If buf is NULL, this function returns
0067    the required initial value for the checksum.
0068    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
0069    much faster. Usage example:
0070 
0071      uLong adler = zlib_adler32(0L, NULL, 0);
0072 
0073      while (read_buffer(buffer, length) != EOF) {
0074        adler = zlib_adler32(adler, buffer, length);
0075      }
0076      if (adler != original_adler) error();
0077 */
0078 static inline uLong zlib_adler32(uLong adler,
0079                  const Byte *buf,
0080                  uInt len)
0081 {
0082     unsigned long s1 = adler & 0xffff;
0083     unsigned long s2 = (adler >> 16) & 0xffff;
0084     int k;
0085 
0086     if (buf == NULL) return 1L;
0087 
0088     while (len > 0) {
0089         k = len < NMAX ? len : NMAX;
0090         len -= k;
0091         while (k >= 16) {
0092             DO16(buf);
0093         buf += 16;
0094             k -= 16;
0095         }
0096         if (k != 0) do {
0097             s1 += *buf++;
0098         s2 += s1;
0099         } while (--k);
0100         s1 %= BASE;
0101         s2 %= BASE;
0102     }
0103     return (s2 << 16) | s1;
0104 }
0105 
0106 #endif /* _Z_UTIL_H */