annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
1 /**
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
2 * utils.c:
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
3 *
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
4 * Useful utilities for general use.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
5 **/
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
6 #ifndef WIN32_LEAN_AND_MEAN
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
7 # define WIN32_LEAN_AND_MEAN
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
8 #endif
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
9 #include <windows.h>
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
10 #include <stdint.h>
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
11
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
12 uint64_t get_system_time_in_milliseconds(void) {
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
13 FILETIME ft;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
14 GetSystemTimeAsFileTime(&ft);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
15 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
16 return ((ul - 116444736000000000ULL)/10000000);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
17 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
18
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
19 unsigned int crc32b(unsigned char *message) {
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
20 int i, j;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
21 unsigned int byte, crc, mask;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
22
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
23 i = 0;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
24 crc = 0xFFFFFFFF;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
25 while (message[i] != 0) {
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
26 byte = message[i]; // Get next byte.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
27 crc = crc ^ byte;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
28 for (j = 7; j >= 0; j--) { // Do eight times.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
29 mask = -(crc & 1);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
30 crc = (crc >> 1) ^ (0xEDB88320 & mask);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
31 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
32 i = i + 1;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
33 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
34 return ~crc;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
35 }