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