Add mg_crc32

This commit is contained in:
cpq committed 2021-03-08 15:40:39 +00:00
1 parent 060bb29cdc
commit d50dc288cd
2 files changed
+11

No files matched your search

+10
View File
@@ -273,6 +273,16 @@ int64_t mg_to64(struct mg_str str) {
return result * neg;
}
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len) {
int i;
crc = ~crc;
while (len--) {
crc ^= *(unsigned char *) buf++;
for (i = 0; i < 8; i++) crc = crc & 1 ? (crc >> 1) ^ 0xedb88320 : crc >> 1;
}
return ~crc;
}
double mg_time(void) {
#if MG_ARCH == MG_ARCH_WIN32
SYSTEMTIME sysnow;