annotate src/utils.c @ 10:42ac054c0231

*: huge refactoring dirtools now uses wchar (wayyy overdue) the timer doesn't have a stupid design anymore we don't use windows.h at all now ...
author Paper <paper@paper.us.eu.org>
date Sun, 11 Feb 2024 19:43:31 -0500
parents 07f0e2f43204
children e6a594f16403
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 **/
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
6 #include "utils.h"
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
7
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
8 #include <sysinfoapi.h>
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
9 #include <stdint.h>
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
10
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
11 uint64_t get_system_time_in_milliseconds(void) {
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
12 FILETIME ft;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
13 GetSystemTimeAsFileTime(&ft);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
14 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
15 return ((ul - 116444736000000000ULL)/10000000);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
16 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
17
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
18 uint32_t crc32b(unsigned char* restrict message) {
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
19 int32_t i, j;
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
20 uint32_t byte, crc, mask;
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
21
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
22 crc = 0xFFFFFFFF;
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
23 for (i = 0; message[i] != 0; i++) {
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
24 byte = message[i]; // Get next byte.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
25 crc = crc ^ byte;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
26 for (j = 7; j >= 0; j--) { // Do eight times.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
27 mask = -(crc & 1);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
28 crc = (crc >> 1) ^ (0xEDB88320 & mask);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
29 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
30 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
31 return ~crc;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
32 }