1111#include "uv_mapping.h"
1212
1313
14- #define UVWASI__WIN_TIME_AND_RETURN (handle , time ) \
14+ #define UVWASI__WIN_TIME_AND_RETURN (handle , get_times , time ) \
1515 do { \
1616 FILETIME create; \
1717 FILETIME exit; \
1818 FILETIME system; \
1919 FILETIME user; \
20- SYSTEMTIME sys_system; \
21- SYSTEMTIME sys_user; \
22- if (0 == GetProcessTimes((handle), &create, &exit, &system, &user)) { \
20+ if (0 == get_times((handle), &create, &exit, &system, &user)) { \
2321 return uvwasi__translate_uv_error( \
2422 uv_translate_sys_error(GetLastError()) \
2523 ); \
2624 } \
2725 \
28- if (0 == FileTimeToSystemTime(&system, &sys_system)) { \
29- return uvwasi__translate_uv_error( \
30- uv_translate_sys_error(GetLastError()) \
31- ); \
32- } \
33- \
34- if (0 == FileTimeToSystemTime(&user, &sys_user)) { \
35- return uvwasi__translate_uv_error( \
36- uv_translate_sys_error(GetLastError()) \
37- ); \
38- } \
39- \
40- (time) = (((uvwasi_timestamp_t)(sys_system.wHour * 3600) + \
41- (sys_system.wMinute * 60) + sys_system.wSecond) * NANOS_PER_SEC) + \
42- ((uvwasi_timestamp_t)(sys_system.wMilliseconds) * 1000000) + \
43- (((uvwasi_timestamp_t)(sys_user.wHour * 3600) + \
44- (sys_user.wMinute * 60) + sys_user.wSecond) * NANOS_PER_SEC) + \
45- ((uvwasi_timestamp_t)(sys_user.wMilliseconds) * 1000000); \
26+ /* FILETIME times are in units of 100 nanoseconds */ \
27+ (time ) = (((uvwasi_timestamp_t ) \
28+ system .dwHighDateTime << 32 | system .dwLowDateTime ) * 100 + \
29+ ((uvwasi_timestamp_t ) \
30+ user .dwHighDateTime << 32 | user .dwLowDateTime ) * 100 ); \
4631 return UVWASI_ESUCCESS ; \
4732 } while (0 )
4833
@@ -137,7 +122,7 @@ uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {
137122
138123uvwasi_errno_t uvwasi__clock_gettime_process_cputime (uvwasi_timestamp_t * time ) {
139124#if defined(_WIN32 )
140- UVWASI__WIN_TIME_AND_RETURN (GetCurrentProcess (), * time );
125+ UVWASI__WIN_TIME_AND_RETURN (GetCurrentProcess (), GetProcessTimes , * time );
141126#elif defined(CLOCK_PROCESS_CPUTIME_ID ) && \
142127 !defined(__APPLE__ ) && \
143128 !defined(__sun )
@@ -150,7 +135,7 @@ uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
150135
151136uvwasi_errno_t uvwasi__clock_gettime_thread_cputime (uvwasi_timestamp_t * time ) {
152137#if defined(_WIN32 )
153- UVWASI__WIN_TIME_AND_RETURN (GetCurrentThread (), * time );
138+ UVWASI__WIN_TIME_AND_RETURN (GetCurrentThread (), GetThreadTimes , * time );
154139#elif defined(__APPLE__ )
155140 UVWASI__OSX_THREADTIME_AND_RETURN (* time );
156141#elif defined(CLOCK_THREAD_CPUTIME_ID ) && !defined(__sun ) && !defined(__PASE__ )
0 commit comments