forked from stlink-org/stlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsys_time.c
More file actions
38 lines (29 loc) · 936 Bytes
/
Copy pathsys_time.c
File metadata and controls
38 lines (29 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdint.h>
#include "sys_time.h"
#ifndef STLINK_HAVE_SYS_TIME_H
#include <time.h>
/* Simple gettimeofday implementation */
int32_t gettimeofday(struct timeval *tv, struct timezone *tz) {
FILETIME ftime;
ULARGE_INTEGER ulint;
static int32_t tzflag = 0;
if(NULL != tv) {
GetSystemTimeAsFileTime(&ftime);
ulint.LowPart = ftime.dwLowDateTime;
ulint.HighPart = ftime.dwHighDateTime;
ulint.QuadPart -= 116444736000000000LL; // shift base to unix epoch
ulint.QuadPart /= 10LL; // 100ns ticks to microseconds
tv->tv_sec = (int32_t) (ulint.QuadPart / 1000000LL);
tv->tv_usec = (int32_t) (ulint.QuadPart % 1000000LL);
}
if(NULL != tz) {
if(!tzflag) {
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif //STLINK_HAVE_SYS_TIME_H