From a42a0c2e715d6783a6f9b75a8f2c9a48bf499c47 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 1 Dec 2007 21:51:20 +0100 Subject: [PATCH] Windows: Implement gettimeofday(). Signed-off-by: Johannes Sixt --- compat/mingw.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index c6a5c1b21..57af486b7 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -38,7 +38,20 @@ int mkstemp(char *template) int gettimeofday(struct timeval *tv, void *tz) { - return -1; + SYSTEMTIME st; + struct tm tm; + GetSystemTime(&st); + tm.tm_year = st.wYear-1900; + tm.tm_mon = st.wMonth-1; + tm.tm_mday = st.wDay; + tm.tm_hour = st.wHour; + tm.tm_min = st.wMinute; + tm.tm_sec = st.wSecond; + tv->tv_sec = tm_to_time_t(&tm); + if (tv->tv_sec < 0) + return -1; + tv->tv_usec = st.wMilliseconds*1000; + return 0; } int poll(struct pollfd *ufds, unsigned int nfds, int timeout) -- 2.26.2