forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgettimeofday.c
30 lines (26 loc) · 1.29 KB
/
gettimeofday.c
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
/***********************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License, with */
/* the special exception on linking described in file ../../LICENSE. */
/* */
/***********************************************************************/
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <time.h>
#include "unixsupport.h"
/* Unix epoch as a Windows timestamp in hundreds of ns */
#define epoch_ft 116444736000000000.0;
CAMLprim value unix_gettimeofday(value unit)
{
FILETIME ft;
double tm;
GetSystemTimeAsFileTime(&ft);
tm = *(uint64_t *)&ft - epoch_ft; /* shift to Epoch-relative time */
return copy_double(tm * 1e-7); /* tm is in 100ns */
}