]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/os-genunix.cpp
audio.engine.test: cleanup using
[factor.git] / vm / os-genunix.cpp
index 9e7804caf09656e9fecd2e0ea3736179a2636c84..90a981ef31121c9692a8aa4ba6d1eb6b7a5a2845 100644 (file)
@@ -1,40 +1,38 @@
 #include "master.hpp"
+#include <time.h>
 
-namespace factor
-{
+namespace factor {
 
-void c_to_factor_toplevel(cell quot)
-{
-       c_to_factor(quot,vm);
-}
+void factor_vm::c_to_factor_toplevel(cell quot) { c_to_factor(quot); }
 
-void init_signals()
-{
-       unix_init_signals();
-}
+void factor_vm::init_signals() { unix_init_signals(); }
 
-void early_init() { }
+void early_init() {}
 
 #define SUFFIX ".image"
 #define SUFFIX_LEN 6
 
-const char *default_image_path()
-{
-       const char *path = vm_executable_path();
+// You must free() the result yourself.
+const char* default_image_path() {
+  const char* path = vm_executable_path();
 
-       if(!path)
-               return "factor.image";
+  if (!path)
+    return strdup("factor.image");
 
-       /* We can't call strlen() here because with gcc 4.1.2 this
-       causes an internal compiler error. */
-       int len = 0;
-       const char *iter = path;
-       while(*iter) { len++; iter++; }
+  size_t len = strlen(path);
+  char* new_path = (char *)malloc(len + SUFFIX_LEN + 1);
+  memcpy(new_path, path, len);
+  memcpy(new_path + len, SUFFIX, SUFFIX_LEN + 1);
+  free(const_cast<char*>(path));
+  return new_path;
+}
 
-       char *new_path = (char *)vm->safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
-       memcpy(new_path,path,len + 1);
-       memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
-       return new_path;
+uint64_t nano_count() {
+  struct timespec t;
+  int ret = clock_gettime(CLOCK_MONOTONIC, &t);
+  if (ret != 0)
+    fatal_error("clock_gettime failed", 0);
+  return (uint64_t)t.tv_sec * 1000000000 + t.tv_nsec;
 }
 
 }