Skip to content

Commit 21d51c0

Browse files
Philip Oakleydscho
authored andcommitted
xcrc32(): create extended crc32 for 64 bit compatibility
On Windows, uInt/uLong are only 32 bits. Create a compatibility function. Signed-off-by: Philip Oakley <[email protected]>
1 parent 4bf4bda commit 21d51c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,4 +1887,10 @@ int print_sha1_ellipsis(void);
18871887
/* Return 1 if the file is empty or does not exists, 0 otherwise. */
18881888
int is_empty_or_missing_file(const char *filename);
18891889

1890+
/*
1891+
* Extended crc32 with 64 bit address range
1892+
* On Windows, uInt/uLong are only 32 bits.
1893+
*/
1894+
extern uLong xcrc32(uLong crc, const unsigned char *buf, size_t bytes);
1895+
18901896
#endif /* CACHE_H */

wrapper.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,19 @@ int is_empty_or_missing_file(const char *filename)
703703

704704
return !st.st_size;
705705
}
706+
707+
uLong xcrc32(uLong crc, const unsigned char *buf, size_t bytes)
708+
{
709+
size_t bytes_rem, off;
710+
bytes_rem = bytes;
711+
off = 0;
712+
while (bytes_rem) {
713+
int crc_bytes = maximum_signed_value_of_type(int);
714+
if (crc_bytes > bytes_rem)
715+
crc_bytes = bytes_rem;
716+
crc = crc32(crc, buf + off, crc_bytes);
717+
off += crc_bytes;
718+
bytes_rem -= crc_bytes;
719+
}
720+
return crc;
721+
}

0 commit comments

Comments
 (0)