]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 #include <thrift/windows/GetTimeOfDay.h>
21 #include <thrift/thrift-config.h>
24 #if defined(__MINGW32__)
28 #if !defined(__MINGW32__)
30 int tz_minuteswest
; /* minutes W of Greenwich */
31 int tz_dsttime
; /* type of dst correction */
35 #if defined(__MINGW32__)
36 int thrift_gettimeofday(struct timeval
* tv
, struct timezone
* tz
) {
37 return gettimeofday(tv
,tz
);
40 #define WIN32_LEAN_AND_MEAN
44 #include <thrift/transport/TTransportException.h>
46 // This code started from a "FREE implementation" posted to Stack Overflow at:
47 // https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows
49 // added: error handling
50 // added: C++ style casts
51 int thrift_gettimeofday(struct timeval
* tp
, struct timezone
* tzp
)
53 // We don't fill it in so prove nobody is looking for the data
56 // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
57 // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
58 // until 00:00:00 January 1, 1970
59 static const uint64_t EPOCH
= static_cast<uint64_t>(116444736000000000ULL);
61 SYSTEMTIME system_time
;
65 GetSystemTime( &system_time
);
66 if (!SystemTimeToFileTime( &system_time
, &file_time
)) {
67 DWORD lastError
= GetLastError();
69 ss
<< "SystemTimeToFileTime failed: 0x" << std::hex
<< lastError
;
70 using apache::thrift::transport::TTransportException
;
71 throw TTransportException(TTransportException::INTERNAL_ERROR
, ss
.str());
73 time
= static_cast<uint64_t>(file_time
.dwLowDateTime
) ;
74 time
+= static_cast<uint64_t>(file_time
.dwHighDateTime
) << 32;
76 tp
->tv_sec
= static_cast<long>((time
- EPOCH
) / 10000000L);
77 tp
->tv_usec
= static_cast<long>(system_time
.wMilliseconds
* 1000);
82 int thrift_sleep(unsigned int seconds
) {
83 ::Sleep(seconds
* 1000);
86 int thrift_usleep(unsigned int microseconds
) {
87 unsigned int milliseconds
= (microseconds
+ 999) / 1000;
88 ::Sleep(milliseconds
);
92 char* thrift_ctime_r(const time_t* _clock
, char* _buf
) {
93 strcpy(_buf
, ctime(_clock
));