-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
#ifndef CLOCK_REALTIME | ||
#define CLOCK_REALTIME 2 | ||
#endif | ||
|
||
// Number of 100 ns intervals from January 1, 1601 till January 1, 1970. | ||
#define UNIX_EPOCH 116444736000000000ULL | ||
|
||
struct timespec { | ||
time_t tv_sec; | ||
long tv_nsec; | ||
}; | ||
|
||
static ULARGE_INTEGER | ||
xgetfiletime (void) | ||
{ | ||
ULARGE_INTEGER current_time; | ||
FILETIME current_time_ft; | ||
|
||
// Return the current time in UTC as a 64-bit value representing the | ||
// number of 100-nanosecond intervals since January 1, 1601. | ||
GetSystemTimePreciseAsFileTime(¤t_time_ft); | ||
current_time.LowPart = current_time_ft.dwLowDateTime; | ||
current_time.HighPart = current_time_ft.dwHighDateTime; | ||
|
||
return current_time; | ||
} | ||
|
||
static int | ||
clock_gettime (const int id, struct timespec* ts) | ||
{ | ||
if (id != CLOCK_REALTIME) { | ||
return -1; | ||
} | ||
|
||
ULARGE_INTEGER current_time = xgetfiletime(); | ||
|
||
// Time from Epoch to now. | ||
ts->tv_sec = (current_time.QuadPart - UNIX_EPOCH) / 10000000; | ||
ts->tv_nsec = ((current_time.QuadPart - UNIX_EPOCH) % 10000000) * 100; | ||
|
||
return 0; | ||
return timespec_get(ts, TIME_UTC) ? 0 : -1; | ||
} |