comparison src/build-msvctools/compat/gettimeofday.c @ 3061:f8299bb6c872

Initial support for native MSVC compilation. * add MSVC support files: compiler wrappers and support libraries * adapt libiconv to work with MSVC * adapt gettext to work with MSVC
author Michael Goffioul <michael.goffioul@gmail.com>
date Mon, 17 Jun 2013 22:43:11 -0400
parents
children
comparison
equal deleted inserted replaced
3060:cbdf4575016d 3061:f8299bb6c872
1 /*
2 * gettimeofday
3 * Implementation according to:
4 * The Open Group Base Specifications Issue 6
5 * IEEE Std 1003.1, 2004 Edition
6 */
7
8 /*
9 * THIS SOFTWARE IS NOT COPYRIGHTED
10 *
11 * This source code is offered for use in the public domain. You may
12 * use, modify or distribute it freely.
13 *
14 * This code is distributed in the hope that it will be useful but
15 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
16 * DISCLAIMED. This includes but is not limited to warranties of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 *
19 * Contributed by:
20 * Danny Smith <dannysmith@users.sourceforge.net>
21 */
22
23 #include <sys/time.h>
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26
27 /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
28 #define _W32_FT_OFFSET (116444736000000000ULL)
29
30
31 int __cdecl gettimeofday(struct timeval *__restrict__ tp,
32 void *__restrict__ tzp __attribute__((unused)))
33 {
34 union {
35 unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
36 FILETIME ft;
37 } _now;
38
39 if(tp)
40 {
41 GetSystemTimeAsFileTime (&_now.ft);
42 tp->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL );
43 tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL);
44 }
45 /* Always return 0 as per Open Group Base Specifications Issue 6.
46 Do not set errno on error. */
47 return 0;
48 }
49