1 #include "running-executable.hpp"
2 #include "directory.hpp"
9 std::string
readlink_generic(std::string path
)
12 if(readlink(path
.c_str(), buf
, sizeof(buf
)) > 0)
14 throw std::runtime_error("Can't determine executable path");
20 std::string
_running_executable()
22 return readlink_generic("/proc/self/exe");
25 #include <mach-o/dyld.h>
26 std::string
_running_executable()
30 _NSGetExecutablePath(buf
, &size
);
33 #elif __WIN32__ || __WIN64__
35 std::string
_running_executable()
38 GetModuleFileName(NULL
, buf
, 8191);
42 std::string
_running_executable()
44 //TODO: This isn't doable?
45 throw std::runtime_error("running_executable() unsupported");
48 #include <sys/param.h>
49 #include <sys/sysctl.h>
50 std::string
_running_executable()
53 int args
[] = {CTL_KERN
, KERN_PROC
, KERN_PROC_PATHNAME
, -1};
55 if(sysctl(args
, 4, buf
, &len
, NULL
, 0) < 0)
56 throw std::runtime_error("Can't determine executable path");
60 std::string
_running_executable()
62 return readlink_generic("/proc/curproc/exe");
66 std::string
_running_executable()
72 std::string
_running_executable()
74 throw std::runtime_error("running_executable() unsupported");
79 std::string
running_executable()
81 return get_absolute_path(_running_executable());