diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/utils.c	Fri Dec 16 20:35:06 2022 -0500
@@ -0,0 +1,35 @@
+/**
+ * utils.c:
+ *
+ * Useful utilities for general use.
+**/
+#ifndef WIN32_LEAN_AND_MEAN
+#  define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#include <stdint.h>
+
+uint64_t get_system_time_in_milliseconds(void) {
+ 	FILETIME ft;
+	GetSystemTimeAsFileTime(&ft);
+	uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
+	return ((ul - 116444736000000000ULL)/10000000);
+}
+
+unsigned int crc32b(unsigned char *message) {
+	int i, j;
+	unsigned int byte, crc, mask;
+
+	i = 0;
+	crc = 0xFFFFFFFF;
+	while (message[i] != 0) {
+		byte = message[i];            // Get next byte.
+		crc = crc ^ byte;
+		for (j = 7; j >= 0; j--) {    // Do eight times.
+			mask = -(crc & 1);
+			crc = (crc >> 1) ^ (0xEDB88320 & mask);
+		}
+		i = i + 1;
+	}
+	return ~crc;
+}