1999-11-16 07:25:48 -08:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
2011-07-27 07:17:02 -07:00
|
|
|
/* OCaml */
|
1999-11-16 07:25:48 -08:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1999-11-16 07:25:48 -08:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
2014-12-27 06:41:49 -08:00
|
|
|
#include <caml/mlvalues.h>
|
|
|
|
#include <caml/alloc.h>
|
1997-09-04 06:45:56 -07:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "unixsupport.h"
|
|
|
|
|
2015-07-17 07:31:05 -07:00
|
|
|
/* Unix epoch as a Windows timestamp in hundreds of ns */
|
|
|
|
#define epoch_ft 116444736000000000.0;
|
1997-09-04 06:45:56 -07:00
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_gettimeofday(value unit)
|
1997-09-04 06:45:56 -07:00
|
|
|
{
|
2015-07-17 07:31:05 -07:00
|
|
|
FILETIME ft;
|
|
|
|
double tm;
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
2015-07-20 04:09:25 -07:00
|
|
|
tm = *(uint64_t *)&ft - epoch_ft; /* shift to Epoch-relative time */
|
2015-07-17 07:31:05 -07:00
|
|
|
return copy_double(tm * 1e-7); /* tm is in 100ns */
|
1997-09-04 06:45:56 -07:00
|
|
|
}
|