]> gitweb.factorcode.org Git - factor.git/blob - vm/os-freebsd.cpp
Move vmpp to vm
[factor.git] / vm / os-freebsd.cpp
1 #include "master.hpp"
2
3 /* From SBCL */
4 const char *vm_executable_path(void)
5 {
6         char path[PATH_MAX + 1];
7
8         if (getosreldate() >= 600024)
9         {
10                 /* KERN_PROC_PATHNAME is available */
11                 size_t len = PATH_MAX + 1;
12                 int mib[4];
13
14                 mib[0] = CTL_KERN;
15                 mib[1] = KERN_PROC;
16                 mib[2] = KERN_PROC_PATHNAME;
17                 mib[3] = -1;
18                 if (sysctl(mib, 4, &path, &len, NULL, 0) != 0)
19                         return NULL;
20         }
21         else
22         {
23                 int size;
24                 size = readlink("/proc/curproc/file", path, sizeof(path) - 1);
25                 if (size < 0)
26                         return NULL;
27                 path[size] = '\0';
28         }
29
30         if(strcmp(path, "unknown") == 0)
31                 return NULL;
32
33         return safe_strdup(path);
34 }