summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/times.c
blob: 725895ec1594f6282b22fd7ef43894df1c11326a (plain)
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
31
32
33
34
35
#include <windows.h>
#include <mlvalues.h>
#include "unixsupport.h"


double to_sec(FILETIME ft) {
  ULARGE_INTEGER tmp;

  tmp.u.LowPart = ft.dwLowDateTime;
  tmp.u.HighPart = ft.dwHighDateTime;

  /* convert to seconds:
     GetProcessTimes returns number of 100-nanosecond intervals */
  return tmp.QuadPart / 1e7;
}


value unix_times(value unit) {

  value res;
  FILETIME creation, exit, stime, utime;

  if (!(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &stime, &utime))) {
    win32_maperr(GetLastError());
    uerror("times", Nothing);
  }

  res = alloc_small(4 * Double_wosize, Double_array_tag);
  Store_double_field(res, 0, to_sec(utime));
  Store_double_field(res, 1, to_sec(stime));
  Store_double_field(res, 2, 0);
  Store_double_field(res, 3, 0);
  return res;

}