]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add crc32_z() and adler32_z() functions with size_t lengths.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 1 Jan 2017 00:57:26 +0000 (16:57 -0800)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 9 Feb 2017 10:21:35 +0000 (11:21 +0100)
adler32.c
crc32.c
zlib.h

index 81c263948af43c3efca6ae70672fcdd4f5a1f070..1ce855e24f370743669c84e58cb30fdd487e16ed 100644 (file)
--- a/adler32.c
+++ b/adler32.c
@@ -60,7 +60,7 @@ static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len
 #endif
 
 /* ========================================================================= */
-uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uint32_t len) {
+uint32_t ZEXPORT adler32_z(uint32_t adler, const unsigned char *buf, size_t len) {
     uint32_t sum2;
     unsigned n;
 
@@ -142,6 +142,11 @@ uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uint32_t len)
     return adler | (sum2 << 16);
 }
 
+/* ========================================================================= */
+uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uint32_t len) {
+    return adler32_z(adler, buf, len);
+}
+
 /* ========================================================================= */
 static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
     uint32_t sum1;
diff --git a/crc32.c b/crc32.c
index 4f38163a498d3f9afc0ba1893fd8f2929a8749b1..4cc50575681cbd9bd1dab2ecdb770f1fff1e7a18 100644 (file)
--- a/crc32.c
+++ b/crc32.c
@@ -64,9 +64,9 @@
 #include "deflate.h"
 
 #if BYTE_ORDER == LITTLE_ENDIAN
-static uint32_t crc32_little(uint32_t, const unsigned char *, z_off64_t);
+static uint32_t crc32_little(uint32_t, const unsigned char *, size_t);
 #elif BYTE_ORDER == BIG_ENDIAN
-static uint32_t crc32_big(uint32_t, const unsigned char *, z_off64_t);
+static uint32_t crc32_big(uint32_t, const unsigned char *, size_t);
 #endif
 
 /* Local functions for crc concatenation */
@@ -211,7 +211,7 @@ const uint32_t * ZEXPORT get_crc_table(void) {
 #define DO4 DO1; DO1; DO1; DO1
 
 /* ========================================================================= */
-uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, z_off64_t len) {
+uint32_t ZEXPORT crc32_z(uint32_t crc, const unsigned char *buf, size_t len) {
     if (buf == NULL) return 0;
 
 #ifdef DYNAMIC_CRC_TABLE
@@ -246,6 +246,9 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, z_off64_t len) {
     return crc ^ 0xffffffff;
 }
 
+uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uint32_t len) {
+    return crc32_z(crc, buf, len);
+}
 
 /*
    This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
@@ -267,7 +270,7 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, z_off64_t len) {
 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
 
 /* ========================================================================= */
-static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, z_off64_t len) {
+static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, size_t len) {
     register uint32_t c;
     register const uint32_t *buf4;
 
@@ -309,7 +312,7 @@ static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, z_off64_t l
 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
 
 /* ========================================================================= */
-static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, z_off64_t len) {
+static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, size_t len) {
     register uint32_t c;
     register const uint32_t *buf4;
 
diff --git a/zlib.h b/zlib.h
index 1f79b33619266967bb2d0168ac610f66856bbce2..597952bc40dd9ee3055308c6a9f20c1a805464f0 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -1661,6 +1661,11 @@ ZEXTERN uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uint3
      if (adler != original_adler) error();
 */
 
+ZEXTERN uint32_t ZEXPORT adler32_z (uint32_t adler, const unsigned char *buf, size_t len);
+/*
+     Same as adler32(), but with a size_t length.
+*/
+
 /*
 ZEXTERN uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off_t len2);
 
@@ -1672,7 +1677,7 @@ ZEXTERN uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off
    negative, the result has no meaning or utility.
 */
 
-ZEXTERN uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, z_off64_t len);
+ZEXTERN uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uint32_t len);
 /*
      Update a running CRC-32 with the bytes buf[0..len-1] and return the
    updated CRC-32.  If buf is NULL, this function returns the required
@@ -1689,6 +1694,11 @@ ZEXTERN uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, z_off64_t
      if (crc != original_crc) error();
 */
 
+ZEXTERN uint32_t ZEXPORT crc32_z (uint32_t crc, const unsigned char *buf, size_t len);
+/*
+     Same as crc32(), but with a size_t length.
+*/
+
 /*
 ZEXTERN uint32_t ZEXPORT crc32_combine(uint32_t crc1, uint32_t crc2, z_off64_t len2);