comparison zlib/adler32.c @ 2690:9ef72ee5c0b0

Update vendored zlib to 1.3.1
author Michael Pavone <pavone@retrodev.com>
date Sun, 15 Jun 2025 15:39:33 -0700
parents 00d788dac91a
children
comparison
equal deleted inserted replaced
2689:bd6e33de0972 2690:9ef72ee5c0b0
4 */ 4 */
5 5
6 /* @(#) $Id$ */ 6 /* @(#) $Id$ */
7 7
8 #include "zutil.h" 8 #include "zutil.h"
9
10 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
11 9
12 #define BASE 65521U /* largest prime smaller than 65536 */ 10 #define BASE 65521U /* largest prime smaller than 65536 */
13 #define NMAX 5552 11 #define NMAX 5552
14 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 12 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
15 13
58 # define MOD28(a) a %= BASE 56 # define MOD28(a) a %= BASE
59 # define MOD63(a) a %= BASE 57 # define MOD63(a) a %= BASE
60 #endif 58 #endif
61 59
62 /* ========================================================================= */ 60 /* ========================================================================= */
63 uLong ZEXPORT adler32_z(adler, buf, len) 61 uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
64 uLong adler;
65 const Bytef *buf;
66 z_size_t len;
67 {
68 unsigned long sum2; 62 unsigned long sum2;
69 unsigned n; 63 unsigned n;
70 64
71 /* split Adler-32 into component sums */ 65 /* split Adler-32 into component sums */
72 sum2 = (adler >> 16) & 0xffff; 66 sum2 = (adler >> 16) & 0xffff;
129 /* return recombined sums */ 123 /* return recombined sums */
130 return adler | (sum2 << 16); 124 return adler | (sum2 << 16);
131 } 125 }
132 126
133 /* ========================================================================= */ 127 /* ========================================================================= */
134 uLong ZEXPORT adler32(adler, buf, len) 128 uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
135 uLong adler;
136 const Bytef *buf;
137 uInt len;
138 {
139 return adler32_z(adler, buf, len); 129 return adler32_z(adler, buf, len);
140 } 130 }
141 131
142 /* ========================================================================= */ 132 /* ========================================================================= */
143 local uLong adler32_combine_(adler1, adler2, len2) 133 local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
144 uLong adler1;
145 uLong adler2;
146 z_off64_t len2;
147 {
148 unsigned long sum1; 134 unsigned long sum1;
149 unsigned long sum2; 135 unsigned long sum2;
150 unsigned rem; 136 unsigned rem;
151 137
152 /* for negative len, return invalid adler32 as a clue for debugging */ 138 /* for negative len, return invalid adler32 as a clue for debugging */
167 if (sum2 >= BASE) sum2 -= BASE; 153 if (sum2 >= BASE) sum2 -= BASE;
168 return sum1 | (sum2 << 16); 154 return sum1 | (sum2 << 16);
169 } 155 }
170 156
171 /* ========================================================================= */ 157 /* ========================================================================= */
172 uLong ZEXPORT adler32_combine(adler1, adler2, len2) 158 uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
173 uLong adler1;
174 uLong adler2;
175 z_off_t len2;
176 {
177 return adler32_combine_(adler1, adler2, len2); 159 return adler32_combine_(adler1, adler2, len2);
178 } 160 }
179 161
180 uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 162 uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
181 uLong adler1;
182 uLong adler2;
183 z_off64_t len2;
184 {
185 return adler32_combine_(adler1, adler2, len2); 163 return adler32_combine_(adler1, adler2, len2);
186 } 164 }