]> gitweb.factorcode.org Git - factor.git/blob - vm/os-genunix.cpp
rename millis to system-millis, micros to system-micros, add nano-count
[factor.git] / vm / os-genunix.cpp
1 #include "master.hpp"
2 #include <time.h>
3
4 namespace factor
5 {
6
7 void factor_vm::c_to_factor_toplevel(cell quot)
8 {
9         c_to_factor(quot,this);
10 }
11
12 void init_signals()
13 {
14         unix_init_signals();
15 }
16
17 void early_init() { }
18
19 #define SUFFIX ".image"
20 #define SUFFIX_LEN 6
21
22 /* You must delete[] the result yourself. */
23 const char *default_image_path()
24 {
25         const char *path = vm_executable_path();
26
27         if(!path)
28                 return "factor.image";
29
30         int len = strlen(path);
31         char *new_path = new char[PATH_MAX + SUFFIX_LEN + 1];
32         memcpy(new_path,path,len + 1);
33         memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
34         free(const_cast<char *>(path));
35         return new_path;
36 }
37
38 u64 nano_count()
39 {
40         struct timespec t;
41         int ret;
42         ret = clock_gettime(CLOCK_MONOTONIC,&t);
43         if(ret != 0)
44                 fatal_error("clock_gettime failed", 0);
45         return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
46 }
47
48 }