Skip to content

Commit

Permalink
Merge pull request #1074 from slyshykO/fix_msvc_gettimeofday
Browse files Browse the repository at this point in the history
Fixed gettimeofday for msvc
  • Loading branch information
Nightwalker-87 authored Dec 5, 2020
2 parents 133b9aa + 28c9445 commit 2fb0756
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
31 changes: 22 additions & 9 deletions src/win32/sys_time.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
#include <stdlib.h>
#include <unistd.h>

#include "sys_time.h"

#ifndef STLINK_HAVE_SYS_TIME_H

#include <time.h>

/* Simple gettimeofday implementation without converting Windows time to Linux time */
int gettimeofday(struct timeval *tv, struct timezone *tz) {
FILETIME ftime;
ULARGE_INTEGER ulint;
static int tzflag = 0;

if(NULL != tv) {
GetSystemTimeAsFileTime(&ftime);
ulint.LowPart = ftime.dwLowDateTime;
ulint.HighPart = ftime.dwHighDateTime;

GetSystemTimeAsFileTime(&ftime);
ulint.LowPart = ftime.dwLowDateTime;
ulint.HighPart = ftime.dwHighDateTime;
tv->tv_sec = (long)(ulint.QuadPart / 10000000L);
tv->tv_usec = (long)(ulint.QuadPart % 10000000L);
}

tv->tv_sec = (long)(ulint.QuadPart / 10000000L);
tv->tv_usec = (long)(ulint.QuadPart % 10000000L);
if(NULL != tz) {
if (!tzflag) {
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}

return 0;
(void)tz;
}
#endif //STLINK_HAVE_SYS_TIME_H
5 changes: 1 addition & 4 deletions src/win32/sys_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#include <sys/time.h>
#else

struct timeval {
long tv_sec;
long tv_usec;
};
#include <windows.h>

struct timezone {
int tz_minuteswest;
Expand Down

0 comments on commit 2fb0756

Please sign in to comment.