comparison src/utils.c @ 9:07f0e2f43204

*: add the restrict keyword when necessary also fixed some typos in the README
author Paper
date Fri, 16 Dec 2022 21:55:37 -0500
parents be4835547dd0
children 42ac054c0231
comparison
equal deleted inserted replaced
8:00399cc5f7ce 9:07f0e2f43204
14 GetSystemTimeAsFileTime(&ft); 14 GetSystemTimeAsFileTime(&ft);
15 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime; 15 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
16 return ((ul - 116444736000000000ULL)/10000000); 16 return ((ul - 116444736000000000ULL)/10000000);
17 } 17 }
18 18
19 unsigned int crc32b(unsigned char *message) { 19 uint32_t crc32b(unsigned char* restrict message) {
20 int i, j; 20 int32_t i, j;
21 unsigned int byte, crc, mask; 21 uint32_t byte, crc, mask;
22 22
23 i = 0;
24 crc = 0xFFFFFFFF; 23 crc = 0xFFFFFFFF;
25 while (message[i] != 0) { 24 for (i = 0; message[i] != 0; i++) {
26 byte = message[i]; // Get next byte. 25 byte = message[i]; // Get next byte.
27 crc = crc ^ byte; 26 crc = crc ^ byte;
28 for (j = 7; j >= 0; j--) { // Do eight times. 27 for (j = 7; j >= 0; j--) { // Do eight times.
29 mask = -(crc & 1); 28 mask = -(crc & 1);
30 crc = (crc >> 1) ^ (0xEDB88320 & mask); 29 crc = (crc >> 1) ^ (0xEDB88320 & mask);
31 } 30 }
32 i = i + 1;
33 } 31 }
34 return ~crc; 32 return ~crc;
35 } 33 }