28 std::vector<char> path_buffer;
31 _NSGetExecutablePath(
nullptr, &read);
32 path_buffer.resize(read + 1);
33 if (_NSGetExecutablePath(path_buffer.data(), &read) != 0)
return {};
34 return fs::path{path_buffer.data()};
39 path_buffer.resize(std::max(path_buffer.size(),
static_cast<size_t>(128)) * 2);
40 read = GetModuleFileNameA(
nullptr, path_buffer.data(),
static_cast<DWORD
>(path_buffer.size()));
41 }
while (read == path_buffer.size());
44 path_buffer.resize(read + 1);
45 path_buffer.back() = 0;
46 return fs::path{path_buffer.data()};
49 if (fs::exists(
"/proc/self/exe"))
return fs::canonical(
"/proc/self/exe");
55std::string
exec(std::string cmd) {
56 std::array<char, 128> buffer;
58 std::unique_ptr<FILE,
decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
59 if (!pipe)
error(
"popen() failed!");
60 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) result += buffer.data();