-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gettimeofday() implementation - Upstream 828566b
- Loading branch information
1 parent
ec9e9f0
commit 4b05b62
Showing
30 changed files
with
1,224 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Source: https://stackoverflow.com/questions/10905892/equivalent-of-gettimeofday-for-windows | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#include <stdint.h> // portable: uint64_t MSVC: __int64 | ||
|
||
// MSVC defines this in winsock2.h!? | ||
typedef struct timeval { | ||
long tv_sec; | ||
long tv_usec; | ||
} timeval; | ||
|
||
int gettimeofday(struct timeval* tp, struct timezone* tzp) | ||
{ | ||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's | ||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) | ||
// until 00:00:00 January 1, 1970 | ||
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); | ||
|
||
SYSTEMTIME system_time; | ||
FILETIME file_time; | ||
uint64_t time; | ||
|
||
GetSystemTime(&system_time); | ||
SystemTimeToFileTime(&system_time, &file_time); | ||
time = ((uint64_t)file_time.dwLowDateTime); | ||
time += ((uint64_t)file_time.dwHighDateTime) << 32; | ||
|
||
tp->tv_sec = (long)((time - EPOCH) / 10000000L); | ||
tp->tv_usec = (long)(system_time.wMilliseconds * 1000); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.