mirror of
https://gitea.invidious.io/iv-org/litespeed-quic.git
synced 2024-08-15 00:53:43 +00:00
Merge pull request #14 from dtikhonov/201804201611-fix-windows-gettime
Fix Windows gettimeofday() implementation - were off by 10
This commit is contained in:
commit
64b2228feb
1 changed files with 13 additions and 11 deletions
|
@ -3,6 +3,7 @@
|
||||||
* LSQUIC Logger implementation.
|
* LSQUIC Logger implementation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -124,7 +125,7 @@ lsquic_printf (const char *fmt, ...)
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
#define DELTA_EPOCH_IN_TICKS 116444736000000000Ui64
|
||||||
struct timezone
|
struct timezone
|
||||||
{
|
{
|
||||||
time_t tz_minuteswest; /* minutes W of Greenwich */
|
time_t tz_minuteswest; /* minutes W of Greenwich */
|
||||||
|
@ -135,22 +136,19 @@ static int
|
||||||
gettimeofday (struct timeval *tv, struct timezone *tz)
|
gettimeofday (struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
unsigned __int64 tmpres = 0;
|
uint64_t tmpres;
|
||||||
static int tzflag;
|
static int tzflag;
|
||||||
|
|
||||||
if (NULL != tv)
|
if (NULL != tv)
|
||||||
{
|
{
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
|
|
||||||
tmpres |= ft.dwHighDateTime;
|
tmpres = ((uint64_t) ft.dwHighDateTime << 32)
|
||||||
tmpres <<= 32;
|
| (ft.dwLowDateTime);
|
||||||
tmpres |= ft.dwLowDateTime;
|
|
||||||
|
|
||||||
/*converting file time to unix epoch */
|
tmpres -= DELTA_EPOCH_IN_TICKS;
|
||||||
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
tv->tv_sec = tmpres / 10000000;
|
||||||
tmpres /= 10; /*convert into microseconds */
|
tv->tv_usec = tmpres % 1000000;
|
||||||
tv->tv_sec = (long) (tmpres / 1000000UL);
|
|
||||||
tv->tv_usec = (long) (tmpres % 1000000UL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != tz)
|
if (NULL != tz)
|
||||||
|
@ -179,8 +177,12 @@ print_timestamp (void)
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
errno_t e;
|
||||||
|
#endif
|
||||||
time_t t = tv.tv_sec;
|
time_t t = tv.tv_sec;
|
||||||
localtime_s(&tm, &t); // Could be a macro, but then a type mismatch.
|
e = localtime_s(&tm, &t);
|
||||||
|
assert(!e);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
localtime_r(&tv.tv_sec, &tm);
|
localtime_r(&tv.tv_sec, &tm);
|
||||||
|
|
Loading…
Reference in a new issue