mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-13 10:15:00 +00:00
Add mg_crc32
This commit is contained in:
+10
@@ -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;
|
||||
|
||||
@@ -12,6 +12,7 @@ bool mg_globmatch(const char *pattern, int plen, const char *s, int n);
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
uint16_t mg_ntohs(uint16_t net);
|
||||
uint32_t mg_ntohl(uint32_t net);
|
||||
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
||||
char *mg_hexdump(const void *buf, size_t len);
|
||||
char *mg_hex(const void *buf, int len, char *dst);
|
||||
void mg_unhex(const char *buf, int len, unsigned char *to);
|
||||
|
||||
Reference in New Issue
Block a user