jdk/src/share/native/java/util/zip/zlib-1.2.5/zadler32.c
author sherman
Tue, 29 Nov 2011 11:39:59 -0800
changeset 11112 6d340c7b6a32
permissions -rw-r--r--
7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5 Summary: updated to zlib-1.2.5 Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11112
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     1
/*
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     3
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
     9
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    14
 * accompanied this code).
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    15
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    19
 *
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    22
 * questions.
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    23
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    24
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    25
/* adler32.c -- compute the Adler-32 checksum of a data stream
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    26
 * Copyright (C) 1995-2007 Mark Adler
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    27
 * For conditions of distribution and use, see copyright notice in zlib.h
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    28
 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    29
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    30
/* @(#) $Id$ */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    31
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    32
#include "zutil.h"
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    33
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    34
#define local static
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    35
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    36
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    37
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    38
#define BASE 65521UL    /* largest prime smaller than 65536 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    39
#define NMAX 5552
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    40
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    41
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    42
#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    43
#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    44
#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    45
#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    46
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    47
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    48
/* use NO_DIVIDE if your processor does not do division in hardware */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    49
#ifdef NO_DIVIDE
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    50
#  define MOD(a) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    51
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    52
        if (a >= (BASE << 16)) a -= (BASE << 16); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    53
        if (a >= (BASE << 15)) a -= (BASE << 15); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    54
        if (a >= (BASE << 14)) a -= (BASE << 14); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    55
        if (a >= (BASE << 13)) a -= (BASE << 13); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    56
        if (a >= (BASE << 12)) a -= (BASE << 12); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    57
        if (a >= (BASE << 11)) a -= (BASE << 11); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    58
        if (a >= (BASE << 10)) a -= (BASE << 10); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    59
        if (a >= (BASE << 9)) a -= (BASE << 9); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    60
        if (a >= (BASE << 8)) a -= (BASE << 8); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    61
        if (a >= (BASE << 7)) a -= (BASE << 7); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    62
        if (a >= (BASE << 6)) a -= (BASE << 6); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    63
        if (a >= (BASE << 5)) a -= (BASE << 5); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    64
        if (a >= (BASE << 4)) a -= (BASE << 4); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    65
        if (a >= (BASE << 3)) a -= (BASE << 3); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    66
        if (a >= (BASE << 2)) a -= (BASE << 2); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    67
        if (a >= (BASE << 1)) a -= (BASE << 1); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    68
        if (a >= BASE) a -= BASE; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    69
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    70
#  define MOD4(a) \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    71
    do { \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    72
        if (a >= (BASE << 4)) a -= (BASE << 4); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    73
        if (a >= (BASE << 3)) a -= (BASE << 3); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    74
        if (a >= (BASE << 2)) a -= (BASE << 2); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    75
        if (a >= (BASE << 1)) a -= (BASE << 1); \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    76
        if (a >= BASE) a -= BASE; \
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    77
    } while (0)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    78
#else
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    79
#  define MOD(a) a %= BASE
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    80
#  define MOD4(a) a %= BASE
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    81
#endif
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    82
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    83
/* ========================================================================= */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    84
uLong ZEXPORT adler32(adler, buf, len)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    85
    uLong adler;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    86
    const Bytef *buf;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    87
    uInt len;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    88
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    89
    unsigned long sum2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    90
    unsigned n;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    91
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    92
    /* split Adler-32 into component sums */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    93
    sum2 = (adler >> 16) & 0xffff;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    94
    adler &= 0xffff;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    95
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    96
    /* in case user likes doing a byte at a time, keep it fast */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    97
    if (len == 1) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    98
        adler += buf[0];
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
    99
        if (adler >= BASE)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   100
            adler -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   101
        sum2 += adler;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   102
        if (sum2 >= BASE)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   103
            sum2 -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   104
        return adler | (sum2 << 16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   105
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   106
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   107
    /* initial Adler-32 value (deferred check for len == 1 speed) */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   108
    if (buf == Z_NULL)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   109
        return 1L;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   110
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   111
    /* in case short lengths are provided, keep it somewhat fast */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   112
    if (len < 16) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   113
        while (len--) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   114
            adler += *buf++;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   115
            sum2 += adler;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   116
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   117
        if (adler >= BASE)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   118
            adler -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   119
        MOD4(sum2);             /* only added so many BASE's */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   120
        return adler | (sum2 << 16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   121
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   122
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   123
    /* do length NMAX blocks -- requires just one modulo operation */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   124
    while (len >= NMAX) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   125
        len -= NMAX;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   126
        n = NMAX / 16;          /* NMAX is divisible by 16 */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   127
        do {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   128
            DO16(buf);          /* 16 sums unrolled */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   129
            buf += 16;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   130
        } while (--n);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   131
        MOD(adler);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   132
        MOD(sum2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   133
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   134
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   135
    /* do remaining bytes (less than NMAX, still just one modulo) */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   136
    if (len) {                  /* avoid modulos if none remaining */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   137
        while (len >= 16) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   138
            len -= 16;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   139
            DO16(buf);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   140
            buf += 16;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   141
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   142
        while (len--) {
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   143
            adler += *buf++;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   144
            sum2 += adler;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   145
        }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   146
        MOD(adler);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   147
        MOD(sum2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   148
    }
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   149
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   150
    /* return recombined sums */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   151
    return adler | (sum2 << 16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   152
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   153
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   154
/* ========================================================================= */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   155
local uLong adler32_combine_(adler1, adler2, len2)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   156
    uLong adler1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   157
    uLong adler2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   158
    z_off64_t len2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   159
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   160
    unsigned long sum1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   161
    unsigned long sum2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   162
    unsigned rem;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   163
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   164
    /* the derivation of this formula is left as an exercise for the reader */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   165
    rem = (unsigned)(len2 % BASE);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   166
    sum1 = adler1 & 0xffff;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   167
    sum2 = rem * sum1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   168
    MOD(sum2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   169
    sum1 += (adler2 & 0xffff) + BASE - 1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   170
    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   171
    if (sum1 >= BASE) sum1 -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   172
    if (sum1 >= BASE) sum1 -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   173
    if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   174
    if (sum2 >= BASE) sum2 -= BASE;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   175
    return sum1 | (sum2 << 16);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   176
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   177
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   178
/* ========================================================================= */
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   179
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   180
    uLong adler1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   181
    uLong adler2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   182
    z_off_t len2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   183
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   184
    return adler32_combine_(adler1, adler2, len2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   185
}
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   186
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   187
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   188
    uLong adler1;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   189
    uLong adler2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   190
    z_off64_t len2;
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   191
{
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   192
    return adler32_combine_(adler1, adler2, len2);
6d340c7b6a32 7110149: Update the JDK8 bundled zlib library to the latest version 1.2.5
sherman
parents:
diff changeset
   193
}