aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-10-18 14:19:32 +0200
committerMartin Willi <martin@revosec.ch>2014-06-04 15:53:01 +0200
commit4de7401a980db8e1b074e74723a8aa84c8621d16 (patch)
treeaa2451851e53575a4e406d401e8c3c07d2ed6f4f
parent965e846cc31050078399f724ecc1d67b1937bcd8 (diff)
downloadstrongswan-4de7401a980db8e1b074e74723a8aa84c8621d16.tar.bz2
strongswan-4de7401a980db8e1b074e74723a8aa84c8621d16.tar.xz
windows: Provide a time_monotonic() based on GetTickCount64()
-rw-r--r--src/libstrongswan/utils/utils.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c
index 70fd1cb31..dc0608627 100644
--- a/src/libstrongswan/utils/utils.c
+++ b/src/libstrongswan/utils/utils.c
@@ -15,6 +15,13 @@
*/
#define _GNU_SOURCE /* for memrchr */
+#ifdef WIN32
+/* for GetTickCount64, Windows 7 */
+# define _WIN32_WINNT 0x0601
+#endif
+
+#include "utils.h"
+
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
@@ -441,6 +448,19 @@ void closefrom(int lowfd)
*/
time_t time_monotonic(timeval_t *tv)
{
+#ifdef WIN32
+ ULONGLONG ms;
+ time_t s;
+
+ ms = GetTickCount64();
+ s = ms / 1000;
+ if (tv)
+ {
+ tv->tv_sec = s;
+ tv->tv_usec = (ms - (s * 1000)) * 1000;
+ }
+ return s;
+#else /* !WIN32 */
#if defined(HAVE_CLOCK_GETTIME) && \
(defined(HAVE_CONDATTR_CLOCK_MONOTONIC) || \
defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
@@ -472,6 +492,7 @@ time_t time_monotonic(timeval_t *tv)
return -1;
}
return tv->tv_sec;
+#endif /* !WIN32 */
}
/**