+#ifdef WIN32
+/*
+ * WIN32 does not have gettimeofday and struct timeval. This is a quick and dirty
+ * replacement.
+ */
+#include <sys/timeb.h>
+
+struct timeval {
+ time_t tv_sec; /* seconds */
+ long tv_usec; /* microseconds */
+};
+
+struct __timezone {
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+static gettimeofday(struct timeval *t, struct __timezone *tz) {
+
+ struct timeb current_time;
+
+ _ftime(¤t_time);
+
+ t->tv_sec = current_time.time;
+ t->tv_usec = current_time.millitm * 1000;
+}
+
+#endif
+/*
+ * normilize time as returned by gettimeofday. usec part must
+ * be always >= 0
+ */
+static void normalize_time(struct timeval *t)
+{
+ if(t->tv_usec < 0) {
+ t->tv_sec--;
+ t->tv_usec += 1000000L;
+ }
+}
+