/* librock/acquired/zlib-1.1.3/adler32.c $Log: adler32.c,v $ Revision 1.1 2002/03/18 17:14:41 Administrator Moved. Updated to 1.1.4 Revision 1.5 2002/03/12 18:05:57 Official changes for 1.1.4 Update copyright notice for 1.1.4 Revision 1.4 2002/02/05 16:42:22 Administrator Reset version numbers Revision 1.4 2002/02/02 20:01:21 Administrator added log Revision 1.3 2002/01/30 16:07:42 forrest@mibsoftware.com rights=#1 Renamed some .h files Revision 1.2 2002/01/29 04:18:10 forrest@mibsoftware.com rights=#1 Lidesc and space/tab clean up Added this section at the top for librock_LIDESC license awareness. See http://www.mibsoftware.com/librock librock_ACQUIRED: 2001-10-23 ftp://ftp.uu.net/graphics/png/src/zlib-1.1.3.tar.gz http://www.gzip.org/zlib/ rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ #ifndef librock_ISOLATED /**************************************************************/ #define librock_IMPLEMENT_adler32 #include #include /**************************************************************/ #endif #ifndef librock_NOIMPL_LIDESC_adler32 #ifdef librock_IMPL_LIDESC /**************************************************************/ #include /* librock_LIDESC_HC=d49ece91d0f3402f1ca405bc4ae7b2a989a56ab2 */ #include /* librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ char *librock_LIDESC_adler32[] = { "\n" __FILE__ librock_LIDESC_zlib "\n", "\n" __FILE__ librock_LIDESC_librock "\n", 0 }; /**************************************************************/ #endif #endif /* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* adler32.c -- compute the Adler-32 checksum of a data stream * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ /* @(#) $Id: adler32.c,v 1.1 2002/03/18 17:14:41 Administrator Exp $ */ #include "zlib.h" #define BASE 65521L /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ #define DO1(buf,i) {s1 += buf[i]; s2 += s1;} #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); #define DO16(buf) DO8(buf,0); DO8(buf,8); /* ========================================================================= */ uLong ZEXPORT adler32(adler, buf, len) uLong adler; const Bytef *buf; uInt len; { unsigned long s1 = adler & 0xffff; unsigned long s2 = (adler >> 16) & 0xffff; int k; if (buf == Z_NULL) return 1L; while (len > 0) { k = len < NMAX ? len : NMAX; len -= k; while (k >= 16) { DO16(buf); buf += 16; k -= 16; } if (k != 0) do { s1 += *buf++; s2 += s1; } while (--k); s1 %= BASE; s2 %= BASE; } return (s2 << 16) | s1; }