Guest User

Untitled

a guest
Jul 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. std::string getSelf()
  2. {
  3. char buf[1024] = { 0 };
  4. #ifdef WIN32
  5. DWORD ret = GetModuleFileNameA(NULL, buf, sizeof(buf));
  6. if (ret && ret != sizeof(buf)) {
  7. std::string res(buf);
  8. for (auto &c : res)
  9. if (c == '\\')
  10. c = '/';
  11. return res;
  12. }
  13. #else
  14. ssize_t ret = readlink("/proc/self/exe", buf, sizeof(buf));
  15. if (ret && ret != sizeof(buf))
  16. return buf;
  17. #endif
  18. throw std::exception("Couldn't determine executable path.");
  19. }
Add Comment
Please, Sign In to add comment