Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string getSelf()
- {
- char buf[1024] = { 0 };
- #ifdef WIN32
- DWORD ret = GetModuleFileNameA(NULL, buf, sizeof(buf));
- if (ret && ret != sizeof(buf)) {
- std::string res(buf);
- for (auto &c : res)
- if (c == '\\')
- c = '/';
- return res;
- }
- #else
- ssize_t ret = readlink("/proc/self/exe", buf, sizeof(buf));
- if (ret && ret != sizeof(buf))
- return buf;
- #endif
- throw std::exception("Couldn't determine executable path.");
- }
Add Comment
Please, Sign In to add comment