~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/zutil.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
  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/kernel.h>
 19 
 20 typedef unsigned char  uch;
 21 typedef unsigned short ush;
 22 typedef unsigned long  ulg;
 23 
 24         /* common constants */
 25 
 26 #define STORED_BLOCK 0
 27 #define STATIC_TREES 1
 28 #define DYN_TREES    2
 29 /* The three kinds of block type */
 30 
 31 #define MIN_MATCH  3
 32 #define MAX_MATCH  258
 33 /* The minimum and maximum match lengths */
 34 
 35 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
 36 
 37         /* target dependencies */
 38 
 39         /* Common defaults */
 40 
 41 #ifndef OS_CODE
 42 #  define OS_CODE  0x03  /* assume Unix */
 43 #endif
 44 
 45          /* functions */
 46 
 47 typedef uLong (*check_func) (uLong check, const Byte *buf,
 48                                        uInt len);
 49 
 50 
 51                         /* checksum functions */
 52 
 53 #define BASE 65521L /* largest prime smaller than 65536 */
 54 #define NMAX 5552
 55 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
 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      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
 66    return the updated checksum. If buf is NULL, this function returns
 67    the required initial value for the checksum.
 68    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
 69    much faster. Usage example:
 70 
 71      uLong adler = zlib_adler32(0L, NULL, 0);
 72 
 73      while (read_buffer(buffer, length) != EOF) {
 74        adler = zlib_adler32(adler, buffer, length);
 75      }
 76      if (adler != original_adler) error();
 77 */
 78 static 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 /* _Z_UTIL_H */
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php