Skip to content

Commit 05c4d26

Browse files
author
Philip Oakley
committed
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 b6e4203 commit 05c4d26

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cache.h

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

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

wrapper.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,17 @@ 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 > (size_t)INTMAX_MAX) {
713+
int crc_bytes = (bytes_rem > (size_t)INTMAX_MAX) ? (size_t)INTMAX_MAX : bytes_rem;
714+
crc = crc32(crc, buf + off, crc_bytes);
715+
off += crc_bytes;
716+
bytes_rem -= crc_bytes;
717+
}
718+
return crc;
719+
}

0 commit comments

Comments
 (0)