]> henry.ined.fr Git - .git/commitdiff
* timeval.h (Module): Added included file to make use of
authorN. Brouard <brouard@ined.fr>
Tue, 17 Jun 2003 20:08:00 +0000 (20:08 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 17 Jun 2003 20:08:00 +0000 (20:08 +0000)
gettimeofday working on win32 with cygwin.

src/timeval.h [new file with mode: 0644]

diff --git a/src/timeval.h b/src/timeval.h
new file mode 100644 (file)
index 0000000..3cdb724
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * timeval.h    1.0 01/12/19\r
+ *\r
+ * Defines gettimeofday, timeval, etc. for Win32\r
+ *\r
+ * By Wu Yongwei\r
+ *\r
+ */\r
+\r
+#ifndef _TIMEVAL_H\r
+#define _TIMEVAL_H\r
+\r
+#ifdef _WIN32\r
+\r
+#define WIN32_LEAN_AND_MEAN\r
+#include <windows.h>\r
+#include <time.h>\r
+\r
+#ifndef __GNUC__\r
+#define EPOCHFILETIME (116444736000000000i64)\r
+#else\r
+#define EPOCHFILETIME (116444736000000000LL)\r
+#endif\r
+\r
+struct timeval {\r
+    long tv_sec;        /* seconds */\r
+    long tv_usec;  /* microseconds */\r
+};\r
+\r
+struct timezone {\r
+    int tz_minuteswest; /* minutes W of Greenwich */\r
+    int tz_dsttime;     /* type of dst correction */\r
+};\r
+\r
+__inline int gettimeofday(struct timeval *tv, struct timezone *tz)\r
+{\r
+    FILETIME        ft;\r
+    LARGE_INTEGER   li;\r
+    __int64         t;\r
+    static int      tzflag;\r
+\r
+    if (tv)\r
+    {\r
+        GetSystemTimeAsFileTime(&ft);\r
+        li.LowPart  = ft.dwLowDateTime;\r
+        li.HighPart = ft.dwHighDateTime;\r
+        t  = li.QuadPart;       /* In 100-nanosecond intervals */\r
+        t -= EPOCHFILETIME;     /* Offset to the Epoch time */\r
+        t /= 10;                /* In microseconds */\r
+        tv->tv_sec  = (long)(t / 1000000);\r
+        tv->tv_usec = (long)(t % 1000000);\r
+    }\r
+\r
+    if (tz)\r
+    {\r
+        if (!tzflag)\r
+        {\r
+            _tzset();\r
+            tzflag++;\r
+        }\r
+        tz->tz_minuteswest = _timezone / 60;\r
+        tz->tz_dsttime = _daylight;\r
+    }\r
+\r
+    return 0;\r
+}\r
+\r
+#else  /* _WIN32 */\r
+\r
+#include <sys/time.h>\r
+\r
+#endif /* _WIN32 */\r
+\r
+#endif /* _TIMEVAL_H */\r
+\r
+\r