Mercurial > hg > fxanalyse
comparison future.c @ 81:be814b934eca
Implement gettimeofday()
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 18 Mar 2013 12:36:34 +0100 |
parents | 9d57d1fcbcd5 |
children | 4102fe614df2 |
comparison
equal
deleted
inserted
replaced
80:46fe62febcd0 | 81:be814b934eca |
---|---|
1 /* welcome in the 2012 */ | 1 /* welcome in the 2012 */ |
2 | 2 |
3 /* required by CVI */ | 3 /* required by CVI */ |
4 #include <ansi_c.h> | 4 #include <ansi_c.h> |
5 | |
6 /* time functions */ | |
7 #include <windows.h> | |
8 | |
9 #include "future.h" | |
10 | |
5 | 11 |
6 /* an implementation of the C99 `round` function based on `floor` and `ceil` */ | 12 /* an implementation of the C99 `round` function based on `floor` and `ceil` */ |
7 double round(double x) | 13 double round(double x) |
8 { | 14 { |
9 if (x >= 0.0) { | 15 if (x >= 0.0) { |
16 if (x - y >= 0.5) | 22 if (x - y >= 0.5) |
17 y -= 1.0; | 23 y -= 1.0; |
18 return y; | 24 return y; |
19 } | 25 } |
20 } | 26 } |
27 | |
28 | |
29 /* implement high resolution time service */ | |
30 int gettimeofday(struct timeval *tp, struct timezone *tzp) | |
31 { | |
32 /* difference between 1970-01-01 and 1601-01-01 | |
33 in 100-nanoseconds intervals */ | |
34 const unsigned __int64 shift = 116444736000000000ULL; | |
35 union { | |
36 FILETIME ft; | |
37 unsigned __int64 integer; /* 100-nanoseconds since 1601-01-01 */ | |
38 } now; | |
39 | |
40 /* retrive system time in UTC. the resolution is limited to the resolution | |
41 of the system timer, which is typically in the range of 10 milliseconds | |
42 to 16 milliseconds */ | |
43 GetSystemTimeAsFileTime(&now.ft); | |
44 | |
45 /* shift to epoch and truncate to microseconds */ | |
46 now.integer = (now.integer - shift) / 10LL; | |
47 | |
48 tp->tv_usec = (long)(now.integer % 1000000LL); | |
49 tp->tv_sec = (long)(now.integer / 1000000LL); | |
50 | |
51 /* FIXME CVI redefines the epoch as seconds since 1900-01-01 ! */ | |
52 tp->tv_sec += 2208988800; | |
53 | |
54 return 0; | |
55 } | |
56 | |
57 | |
58 static struct tm * copy_tm_result(struct tm *dest, struct tm const *src) | |
59 { | |
60 if (! src) | |
61 return NULL; | |
62 *dest = *src; | |
63 return dest; | |
64 } | |
65 | |
66 | |
67 struct tm * gmtime_r(time_t const *t, struct tm *tp) | |
68 { | |
69 return copy_tm_result(tp, gmtime(t)); | |
70 } | |
71 |