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