]> gitweb.factorcode.org Git - factor.git/blob - vm/os-freebsd.cpp
Re-add Freebsd Support
[factor.git] / vm / os-freebsd.cpp
1 #include "master.hpp"
2
3 namespace factor {
4 char *vm_saved_path;
5
6 /* 
7    FreeBSD needs proc mounted for this function to work.
8    "mount -t procfs proc /proc"
9 */
10
11 const char* vm_executable_path(){
12   ssize_t bufsiz = 4096;
13   while (true) {
14     char* buf = new char [bufsiz + 1];
15     ssize_t size = readlink("/proc/curproc/file", buf, bufsiz);
16     if (size < 0) {
17       fatal_error("Cannot read /proc/curproc/file", errno);
18     }
19     else {
20       if (size < bufsiz) {
21         buf[size] = '\0';
22         const char* ret = safe_strdup(buf);
23         delete[] buf;
24         return ret;
25       } else {
26         delete[] buf;
27         bufsiz *= 2;
28       }
29     }
30   }
31 }
32
33 }