Windows does not provide clock_gettime() natively, so a polyfill should have
been added. This particular one is simple, but doesn't care about monotonic or
realtime type. Source: https://stackoverflow.com/questions/5404277/


-- 
You received this message because you are subscribed to the Google Groups 
"prosody-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prosody-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prosody-dev/09f4172812fb10c10a1c.1677278081%40EI08_MatisseX.
# HG changeset patch
# User Vitaly Orekhov
# Date 1677278010 -10800
#      Sat Feb 25 01:33:30 2023 +0300
# Node ID 09f4172812fb10c10a1cb7ba8237dd9aeaea4973
# Parent  8c6122068cb6272a5791060389c42844c56caf8d
util.time: Add clock_gettime() polyfill for Windows

Windows does not provide clock_gettime() natively, so a polyfill should have
been added. This particular one is simple, but doesn't care about monotonic or
realtime type. Source: https://stackoverflow.com/questions/5404277/

diff -r 8c6122068cb6 -r 09f4172812fb util-src/time.c
--- a/util-src/time.c	Sat Feb 25 01:11:48 2023 +0300
+++ b/util-src/time.c	Sat Feb 25 01:33:30 2023 +0300
@@ -5,6 +5,25 @@
 #include <time.h>
 #include <lua.h>
 
+#ifdef _WIN32
+#include <Windows.h>
+const int CLOCK_REALTIME = 0;
+const int CLOCK_MONOTONIC = 1;
+
+int clock_gettime(int clock_type, struct timespec* spec) {
+	__int64 wintime;
+
+	GetSystemTimeAsFileTime((FILETIME*)&wintime);
+
+	wintime -= 116444736000000000i64;
+
+	spec->tv_sec = wintime / 10000000i64;
+	spec->tv_nsec = wintime % 10000000i64 * 100;
+
+	return 0;
+}
+#endif
+
 static lua_Number tv2number(struct timespec *tv) {
 	return tv->tv_sec + tv->tv_nsec * 1e-9;
 }

Reply via email to