New test.
[mono.git] / mono / io-layer / timefuncs.c
1 /*
2  * timefuncs.c:  performance timer and other time functions
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #include <config.h>
11 #include <glib.h>
12 #include <sys/time.h>
13 #include <stdlib.h>
14
15 #include <mono/io-layer/wapi.h>
16 #include <mono/io-layer/timefuncs-private.h>
17
18 #undef DEBUG
19
20 void _wapi_time_t_to_filetime (time_t timeval, WapiFileTime *filetime)
21 {
22         guint64 ticks;
23         
24         ticks = ((guint64)timeval * 10000000) + 116444736000000000ULL;
25         filetime->dwLowDateTime = ticks & 0xFFFFFFFF;
26         filetime->dwHighDateTime = ticks >> 32;
27 }
28
29 void _wapi_timeval_to_filetime (struct timeval *tv, WapiFileTime *filetime)
30 {
31         guint64 ticks;
32         
33         ticks = ((guint64)tv->tv_sec * 10000000) +
34                 ((guint64)tv->tv_usec * 10) + 116444736000000000ULL;
35         filetime->dwLowDateTime = ticks & 0xFFFFFFFF;
36         filetime->dwHighDateTime = ticks >> 32;
37 }
38
39 gboolean QueryPerformanceCounter(WapiLargeInteger *count G_GNUC_UNUSED)
40 {
41         return(FALSE);
42 }
43
44 gboolean QueryPerformanceFrequency(WapiLargeInteger *freq G_GNUC_UNUSED)
45 {
46         return(FALSE);
47 }
48
49 guint32 GetTickCount (void)
50 {
51         struct timeval tv;
52         guint32 ret;
53         
54         ret=gettimeofday (&tv, NULL);
55         if(ret==-1) {
56                 return(0);
57         }
58         
59         /* This is supposed to return milliseconds since reboot but I
60          * really can't be bothered to work out the uptime, especially
61          * as the 32bit value wraps around every 47 days
62          */
63         ret=(guint32)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
64
65 #ifdef DEBUG
66         g_message ("%s: returning %d", __func__, ret);
67 #endif
68
69         return(ret);
70 }