MCPcopy Create free account
hub / github.com/ccache/ccache / get_executable_path

Function get_executable_path

src/ccache/util/process.cpp:52–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50namespace util {
51
52fs::path
53get_executable_path()
54{
55#ifdef _WIN32
56 std::vector<wchar_t> buf(MAX_PATH);
57 while (true) {
58 DWORD len =
59 GetModuleFileNameW(nullptr, buf.data(), static_cast<DWORD>(buf.size()));
60 if (len == 0) {
61 return {};
62 }
63 if (len < static_cast<DWORD>(buf.size())) {
64 return fs::path(std::wstring(buf.data(), len));
65 }
66 buf.resize(buf.size() * 2);
67 }
68#elif defined(__APPLE__)
69 uint32_t size = PATH_MAX;
70 std::vector<char> buf(size);
71 if (_NSGetExecutablePath(buf.data(), &size) != 0) {
72 buf.resize(size);
73 if (_NSGetExecutablePath(buf.data(), &size) != 0) {
74 return {};
75 }
76 }
77 return fs::path(buf.data());
78#else
79 char buf[PATH_MAX];
80 ssize_t len = readlink("/proc/self/exe", buf, PATH_MAX - 1);
81 if (len < 0) {
82 return {};
83 }
84 buf[len] = '\0';
85 return fs::path(buf);
86#endif
87}
88
89const char*
90get_hostname()

Callers 1

cache_compilationFunction · 0.85

Calls 3

dataMethod · 0.80
resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected