Debian Codegraph @

cmake/tribits/win_interface/include/gettimeofday.c

raw
1 // @HEADER
2 // *****************************************************************************
3 // TriBITS: Tribal Build, Integrate, and Test System
4 //
5 // Copyright 2013-2016 NTESS and the TriBITS contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include <time.h>
11 #include <Winsock2.h> /* to get timeval struct */
12
13 struct timezone
14 {
15 int tz_minuteswest; /* minutes W of Greenwich */
16 int tz_dsttime; /* type of dst correction */
17 };
18 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
19 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
20 #else
21 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
22 #endif
23
24 static int gettimeofday(struct timeval *tv, struct timezone *tz)
25 {
26 FILETIME ft;
27 unsigned __int64 tmpres = 0;
28 static int tzflag;
29
30 if (NULL != tv)
31 {
32 GetSystemTimeAsFileTime(&ft);
33
34 tmpres |= ft.dwHighDateTime;
35 tmpres <<= 32;
36 tmpres |= ft.dwLowDateTime;
37
38 /*converting file time to unix epoch*/
39 tmpres /= 10; /*convert into microseconds*/
40 tmpres -= DELTA_EPOCH_IN_MICROSECS;
41 tv->tv_sec = (long)(tmpres / 1000000UL);
42 tv->tv_usec = (long)(tmpres % 1000000UL);
43 }
44
45 if (NULL != tz)
46 {
47 if (!tzflag)
48 {
49 _tzset();
50 tzflag++;
51 }
52 tz->tz_minuteswest = _timezone / 60;
53 tz->tz_dsttime = _daylight;
54 }
55
56 return 0;
57 }
58
59