/vm/os-linux.cpp

http://github.com/abeaumont/factor · C++ · 27 lines · 21 code · 5 blank · 1 comment · 1 complexity · 2d60d0de62deb8f8f02395d31a6883ee MD5 · raw file

  1. #include "master.hpp"
  2. namespace factor
  3. {
  4. /* Snarfed from SBCL linux-so.c. You must free() the result yourself. */
  5. const char *vm_executable_path()
  6. {
  7. char *path = new char[PATH_MAX + 1];
  8. int size = readlink("/proc/self/exe", path, PATH_MAX);
  9. if (size < 0)
  10. {
  11. fatal_error("Cannot read /proc/self/exe",0);
  12. return NULL;
  13. }
  14. else
  15. {
  16. path[size] = '\0';
  17. const char *ret = safe_strdup(path);
  18. delete[] path;
  19. return ret;
  20. }
  21. }
  22. }