11
11
#include "uv_mapping.h"
12
12
13
13
14
- #define UVWASI__WIN_TIME_AND_RETURN (handle , time ) \
14
+ #define UVWASI__WIN_TIME_AND_RETURN (handle , get_times , time ) \
15
15
do { \
16
16
FILETIME create; \
17
17
FILETIME exit; \
18
18
FILETIME system; \
19
19
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)) { \
23
21
return uvwasi__translate_uv_error( \
24
22
uv_translate_sys_error(GetLastError()) \
25
23
); \
26
24
} \
27
25
\
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 ); \
46
31
return UVWASI_ESUCCESS ; \
47
32
} while (0 )
48
33
@@ -137,7 +122,7 @@ uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {
137
122
138
123
uvwasi_errno_t uvwasi__clock_gettime_process_cputime (uvwasi_timestamp_t * time ) {
139
124
#if defined(_WIN32 )
140
- UVWASI__WIN_TIME_AND_RETURN (GetCurrentProcess (), * time );
125
+ UVWASI__WIN_TIME_AND_RETURN (GetCurrentProcess (), GetProcessTimes , * time );
141
126
#elif defined(CLOCK_PROCESS_CPUTIME_ID ) && \
142
127
!defined(__APPLE__ ) && \
143
128
!defined(__sun )
@@ -150,7 +135,7 @@ uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
150
135
151
136
uvwasi_errno_t uvwasi__clock_gettime_thread_cputime (uvwasi_timestamp_t * time ) {
152
137
#if defined(_WIN32 )
153
- UVWASI__WIN_TIME_AND_RETURN (GetCurrentThread (), * time );
138
+ UVWASI__WIN_TIME_AND_RETURN (GetCurrentThread (), GetThreadTimes , * time );
154
139
#elif defined(__APPLE__ )
155
140
UVWASI__OSX_THREADTIME_AND_RETURN (* time );
156
141
#elif defined(CLOCK_THREAD_CPUTIME_ID ) && !defined(__sun ) && !defined(__PASE__ )
0 commit comments