Project Alice
Loading...
Searching...
No Matches
pcp_gettimeofday.c
Go to the documentation of this file.
1/*
2 Copyright (c) 2014 by Cisco Systems, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#else
29#include "default_config.h"
30#endif
31
32#ifndef HAVE_GETTIMEOFDAY
33#include <windows.h>
34#include <time.h>
35#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
36#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
37#else /* defined(_MSC_VER) || defined(_MSC_EXTENSIONS)*/
38#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
39#endif /* defined(_MSC_VER) || defined(_MSC_EXTENSIONS)*/
40
41/* custom implementation of the gettimeofday function
42 for Windows platform. */
43
44struct timezone {
45 int tz_minuteswest; /* minutes W of Greenwich */
46 int tz_dsttime; /* type of dst correction */
47};
48
49int gettimeofday(struct timeval *tv, struct timezone *tz)
50{
51 FILETIME ft;
52 unsigned __int64 tmpres=0;
53 static int tzflag=0;
54 long tz_seconds=0;
55 int tz_daylight=0;
56
57 if (NULL != tv) {
58 GetSystemTimeAsFileTime(&ft);
59
60 tmpres|=ft.dwHighDateTime;
61 tmpres<<=32;
62 tmpres|=ft.dwLowDateTime;
63
64 tmpres/=10; /*convert into microseconds*/
65 /*converting file time to unix epoch*/
67 tv->tv_sec=(long)(tmpres / 1000000UL);
68 tv->tv_usec=(long)(tmpres % 1000000UL);
69 }
70
71 if (tz) {
72 if (!tzflag) {
73 _tzset();
74 tzflag++;
75 }
76 if (_get_timezone(&tz_seconds)) {
77 return -1;
78 }
79 if (_get_daylight(&tz_daylight)) {
80 return -1;
81 }
82 tz->tz_minuteswest=tz_seconds / 60;
83 tz->tz_dsttime=tz_daylight;
84 }
85
86 return 0;
87}
88
89#endif //HAVE_GETTIMEOFDAY
int gettimeofday(struct timeval *tv, struct timezone *tz)
#define DELTA_EPOCH_IN_MICROSECS
int tz_minuteswest