OSDN Git Service

Update a number of broken links in comments.
[pg-rex/syncrep.git] / src / port / gettimeofday.c
1 /*
2  * gettimeofday.c
3  *        Win32 gettimeofday() replacement
4  *
5  * $PostgreSQL: pgsql/src/port/gettimeofday.c,v 1.9 2006/03/04 04:44:07 momjian Exp $
6  *
7  * Copyright (c) 2003 SRA, Inc.
8  * Copyright (c) 2003 SKC, Inc.
9  *
10  * Permission to use, copy, modify, and distribute this software and
11  * its documentation for any purpose, without fee, and without a
12  * written agreement is hereby granted, provided that the above
13  * copyright notice and this paragraph and the following two
14  * paragraphs appear in all copies.
15  *
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
17  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
19  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
20  * OF THE POSSIBILITY OF SUCH DAMAGE.
21  *
22  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
25  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
26  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27  */
28
29 #include "c.h"
30
31 #include <sys/time.h>
32
33
34 /* FILETIME of Jan 1 1970 00:00:00. */
35 static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
36
37 /*
38  * timezone information is stored outside the kernel so tzp isn't used anymore.
39  *
40  * Note: this function is not for Win32 high precision timing purpose. See
41  * elapsed_time().
42  */
43 int
44 gettimeofday(struct timeval * tp, struct timezone * tzp)
45 {
46         FILETIME        file_time;
47         SYSTEMTIME      system_time;
48         ULARGE_INTEGER ularge;
49
50         GetSystemTime(&system_time);
51         SystemTimeToFileTime(&system_time, &file_time);
52         ularge.LowPart = file_time.dwLowDateTime;
53         ularge.HighPart = file_time.dwHighDateTime;
54
55         tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
56         tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
57
58         return 0;
59 }