Mercurial > wgsdk
comparison src/utils.c @ 7:be4835547dd0
clean up code, convert git files to hg, etc.
author | Paper |
---|---|
date | Fri, 16 Dec 2022 20:35:06 -0500 |
parents | |
children | 07f0e2f43204 |
comparison
equal
deleted
inserted
replaced
6:8ce85aee15c0 | 7:be4835547dd0 |
---|---|
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 | |
19 unsigned int crc32b(unsigned char *message) { | |
20 int i, j; | |
21 unsigned int byte, crc, mask; | |
22 | |
23 i = 0; | |
24 crc = 0xFFFFFFFF; | |
25 while (message[i] != 0) { | |
26 byte = message[i]; // Get next byte. | |
27 crc = crc ^ byte; | |
28 for (j = 7; j >= 0; j--) { // Do eight times. | |
29 mask = -(crc & 1); | |
30 crc = (crc >> 1) ^ (0xEDB88320 & mask); | |
31 } | |
32 i = i + 1; | |
33 } | |
34 return ~crc; | |
35 } |