GRASS GIS 8 Programmer's Manual  8.5.0dev(2025)-565e82de51
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gettimeofday.c
Go to the documentation of this file.
1 /*
2  * Copied from vcpkg under the MIT license
3  * https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/gettimeofday.c
4  */
5 
6 /*
7  * Copied from PostgreSQL source:
8  * http://doxygen.postgresql.org/gettimeofday_8c_source.html
9  *
10  */
11 
12 /*
13  * gettimeofday.c
14  * Win32 gettimeofday() replacement
15  *
16  * src/port/gettimeofday.c
17  *
18  * Copyright (c) 2003 SRA, Inc.
19  * Copyright (c) 2003 SKC, Inc.
20  *
21  * Permission to use, copy, modify, and distribute this software and
22  * its documentation for any purpose, without fee, and without a
23  * written agreement is hereby granted, provided that the above
24  * copyright notice and this paragraph and the following two
25  * paragraphs appear in all copies.
26  *
27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
29  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
30  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
36  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
37  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38  */
39 
40 #ifdef _MSC_VER
41 
42 #include <winsock2.h>
43 
44 /* FILETIME of Jan 1 1970 00:00:00. */
45 static const unsigned __int64 epoch = 116444736000000000Ui64;
46 
47 /*
48  * timezone information is stored outside the kernel so tzp isn't used anymore.
49  *
50  * Note: this function is not for Win32 high precision timing purpose. See
51  * elapsed_time().
52  */
53 int gettimeofday(struct timeval *tp, struct timezone *tzp)
54 {
55  FILETIME file_time;
56  SYSTEMTIME system_time;
57  ULARGE_INTEGER ularge;
58 
59  GetSystemTime(&system_time);
60  SystemTimeToFileTime(&system_time, &file_time);
61  ularge.LowPart = file_time.dwLowDateTime;
62  ularge.HighPart = file_time.dwHighDateTime;
63 
64  tp->tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L);
65  tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
66 
67  return 0;
68 }
69 
70 #endif /* _MSC_VER */