7 #include <boost/filesystem/operations.hpp> 9 namespace fs = boost::filesystem;
18 #include <sys/param.h> 21 #define NAMLEN(dirent) strlen((dirent)->d_name) 25 char exe_path[MAXPATHLEN];
26 fs::path aPath(
"/proc/self/exe");
27 if (fs::exists(aPath)) {
29 ssize_t len = readlink(aPath.string().c_str(), exe_path,
sizeof(exe_path));
30 if (len >= 0)
return std::string(exe_path, len);
38 #elif defined __APPLE__ 39 #include <mach-o/dyld.h> 48 char exe_path[MAXPATHLEN];
49 uint32_t size =
sizeof(exe_path);
50 if (_NSGetExecutablePath(exe_path, &size) == 0) {
51 char link_path[MAXPATHLEN];
52 if (realpath(exe_path, link_path))
return link_path;
60 #define WIN32_MEAN_AND_LEAN 66 std::vector<wchar_t> PathName(MAX_PATH);
67 DWORD Size = ::GetModuleFileNameW(NULL, PathName.data(), PathName.size());
70 if (Size == 0)
return "";
74 if (Size == PathName.size())
return "";
78 PathName.resize(Size);
81 std::string PathNameUTF8(MAX_PATH);
82 if (UTF16ToUTF8(PathName.data(), PathName.size(), PathNameUTF8))
return "";
84 return std::string(PathNameUTF8.c_str()());
88 #error GetMainExecutable is not implemented on this host yet. boost::filesystem::path executablePath()
Get the path of the executable.
The namespace where chigraph lives.