~steve-sk2/mingw-w64/oneiric

« back to all changes in this revision

Viewing changes to mingw-w64-crt/misc/gettimeofday.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-11-18 00:04:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101118000446-xe24b423su55onyl
Tags: 1.0+20101003-1
* New maintainer. (Closes: #594371.)
* New upstream snapshot:
  - Includes getopt.h. (Closes: #569914.)
* Build g++ for Win64. (Closes: #600451.)
* Standards-Version 3.9.1 (new packaging).
* Include patch from
  http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64?view=revision&revision=3715
  as suggested by Rafaël Carré.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <errno.h>
10
10
#include <windows.h>
11
11
 
12
 
#define FILETIME_1970 11644473600ull /* seconds between 1/1/1601 and 1/1/1970 */
 
12
#define FILETIME_1970 116444736000000000ull /* seconds between 1/1/1601 and 1/1/1970 */
13
13
#define HECTONANOSEC_PER_SEC 10000000ull
14
14
 
15
15
int getntptimeofday (struct timespec *, struct timezone *);
17
17
int getntptimeofday (struct timespec *tp, struct timezone *z)
18
18
{
19
19
  int res = 0;
20
 
  /* struct _timeb timebuffer; */
21
 
  ULARGE_INTEGER fti;
 
20
  union {
 
21
    unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
 
22
    FILETIME ft;
 
23
  }  _now;
22
24
  TIME_ZONE_INFORMATION  TimeZoneInformation;
23
25
  DWORD tzi;
24
26
 
39
41
    }
40
42
 
41
43
  if (tp != NULL) {
42
 
    GetSystemTimeAsFileTime ((LPFILETIME) &fti);         /* 100-nanoseconds since 1-1-1601 */
 
44
    GetSystemTimeAsFileTime (&_now.ft);  /* 100-nanoseconds since 1-1-1601 */
43
45
    /* The actual accuracy on XP seems to be 125,000 nanoseconds = 125 microseconds = 0.125 milliseconds */
44
 
    fti.QuadPart -= FILETIME_1970;      /* 100 nano-seconds since 1-1-1970 */
45
 
    tp->tv_sec = fti.QuadPart / HECTONANOSEC_PER_SEC;   /* seconds since 1-1-1970 */
46
 
    tp->tv_nsec = (long) (fti.QuadPart % HECTONANOSEC_PER_SEC) * 100; /* nanoseconds */
 
46
    _now.ns100 -= FILETIME_1970;        /* 100 nano-seconds since 1-1-1970 */
 
47
    tp->tv_sec = _now.ns100 / HECTONANOSEC_PER_SEC;     /* seconds since 1-1-1970 */
 
48
    tp->tv_nsec = (long) (_now.ns100 % HECTONANOSEC_PER_SEC) * 100; /* nanoseconds */
47
49
  }
48
50
  return res;
49
51
}