7
|
1 /**
|
|
2 * utils.c:
|
|
3 *
|
|
4 * Useful utilities for general use.
|
|
5 **/
|
|
6 #ifndef WIN32_LEAN_AND_MEAN
|
|
7 # define WIN32_LEAN_AND_MEAN
|
|
8 #endif
|
|
9 #include <windows.h>
|
|
10 #include <stdint.h>
|
|
11
|
|
12 uint64_t get_system_time_in_milliseconds(void) {
|
|
13 FILETIME ft;
|
|
14 GetSystemTimeAsFileTime(&ft);
|
|
15 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
|
|
16 return ((ul - 116444736000000000ULL)/10000000);
|
|
17 }
|
|
18
|
9
|
19 uint32_t crc32b(unsigned char* restrict message) {
|
|
20 int32_t i, j;
|
|
21 uint32_t byte, crc, mask;
|
7
|
22
|
|
23 crc = 0xFFFFFFFF;
|
9
|
24 for (i = 0; message[i] != 0; i++) {
|
7
|
25 byte = message[i]; // Get next byte.
|
|
26 crc = crc ^ byte;
|
|
27 for (j = 7; j >= 0; j--) { // Do eight times.
|
|
28 mask = -(crc & 1);
|
|
29 crc = (crc >> 1) ^ (0xEDB88320 & mask);
|
|
30 }
|
|
31 }
|
|
32 return ~crc;
|
|
33 }
|