/**
 * 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);
}

uint32_t crc32b(unsigned char* restrict message) {
	int32_t i, j;
	uint32_t byte, crc, mask;

	crc = 0xFFFFFFFF;
	for (i = 0; message[i] != 0; i++) {
		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);
		}
	}
	return ~crc;
}
