]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/win32unix/gettimeofday.c
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / win32unix / gettimeofday.c
1 /***********************************************************************/
2 /*                                                                     */
3 /*                           Objective Caml                            */
4 /*                                                                     */
5 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
6 /*                                                                     */
7 /*  Copyright 1996 Institut National de Recherche en Informatique et   */
8 /*  en Automatique.  All rights reserved.  This file is distributed    */
9 /*  under the terms of the GNU Library General Public License, with    */
10 /*  the special exception on linking described in file ../../LICENSE.  */
11 /*                                                                     */
12 /***********************************************************************/
13
14 /* $Id: gettimeofday.c 7946 2007-03-01 13:51:24Z xleroy $ */
15
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <time.h>
19
20 #include "unixsupport.h"
21
22 static time_t initial_time = 0; /* 0 means uninitialized */
23 static DWORD initial_tickcount;
24
25 CAMLprim value unix_gettimeofday(value unit)
26 {
27   DWORD tickcount = GetTickCount();
28   if (initial_time == 0 || tickcount < initial_tickcount) {
29     initial_tickcount = tickcount;
30     initial_time = time(NULL);
31     return copy_double((double) initial_time);
32   } else {
33     return copy_double((double) initial_time +
34                        (double) (tickcount - initial_tickcount) * 1e-3);
35   }
36 }