diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index 31b53f50cf4d75f2b32dbadb4e3c2704013212d6..0fed58b590e9f1aaa3fd217a9c884d97edf5622a 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -696,7 +696,14 @@ char* os_cmdshell(void)
 #ifdef __unix__
 clock_t msclock(void)
 {
-	return (clock_t)(xp_timer() * 1000);
+        long double t = roundl(xp_timer() * 1000);
+
+        if (sizeof(clock_t) < 8) {
+                while (t > INT32_MAX)
+                        t -= UINT32_MAX;
+        }
+
+	return (clock_t)t;
 }
 #endif