Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed gettimeofday for MSVC #1074

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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