cURL / Mailing Lists / curl-library / Single Mail

curl-library

gettimeofday() on Win32

From: Gisle Vanem <giva_at_bgnett.no>
Date: Wed, 12 Jan 2005 17:17:42 +0100

Is there any reason why we use either GetLocalTime() with
10ms resulution or timeGetTime() with 1ms resolution when we
can have 100ns resolution using GetSystemTimeAsFileTime()?

Using this would have the added benefit of dropping winmm.lib from
the link command. MSDN tells me this function is supported on
Win95 and up. Anybody knows any problems with it?

Here is a replacement function that should work with gcc:

int gettimeofday (struct timeval *tv, void* tz)
{
  union {
    LONG_LONG ns100; /*time since 1 Jan 1601 in 100ns units */
    FILETIME ft;
  } now;

  GetSystemTimeAsFileTime (&now.ft);
  tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);
  tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);
  return (0);
}

---gv
Received on 2005-01-12