Commits

Anonymous committed a3886be

PR#5734: improved Win32 implementation of Unix.gettimeofday

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12949f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

  • Participants
  • Parent commits 6f58399

Comments (0)

Files changed (2)

 - PR#5698: remove harcoded limit of 200000 labels in emitaux.ml
 - PR#5708: catch Failure"int_of_string" in ocamldebug
 - PR#5731: instruction scheduling forgot to account for destroyed registers
+- PR#5734: improved Win32 implementation of Unix.gettimeofday
 - PR#5735: %apply and %revapply not first class citizens
 - PR#5738: first class module patterns not handled by ocamldep
 - PR#5747: 'unused open' warning not given when compiling with -annot

otherlibs/win32unix/gettimeofday.c

 
 #include "unixsupport.h"
 
+#ifdef HAS_MKTIME
+static double initial_time = 0; /* 0 means uninitialized */
+#else
 static time_t initial_time = 0; /* 0 means uninitialized */
+#endif
 static DWORD initial_tickcount;
 
 CAMLprim value unix_gettimeofday(value unit)
 {
   DWORD tickcount = GetTickCount();
+  SYSTEMTIME st;
+  struct tm tm;
   if (initial_time == 0 || tickcount < initial_tickcount) {
     initial_tickcount = tickcount;
+#ifdef HAS_MKTIME
+    GetLocalTime(&st);
+    tm.tm_sec = st.wSecond;
+    tm.tm_min = st.wMinute;
+    tm.tm_hour = st.wHour;
+    tm.tm_mday = st.wDay;
+    tm.tm_mon = st.wMonth - 1;
+    tm.tm_year = st.wYear - 1900;
+    tm.tm_wday = 0;
+    tm.tm_yday = 0;
+    tm.tm_isdst = -1;
+    initial_time = ((double) mktime(&tm) + (double) st.wMilliseconds * 1e-3);
+#else
     initial_time = time(NULL);
+#endif
     return copy_double((double) initial_time);
   } else {
     return copy_double((double) initial_time +