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