]> git.jsancho.org Git - dungeon-master.git/blob - src/paths.cpp
Search paths for mods and games
[dungeon-master.git] / src / paths.cpp
1 #include <unistd.h>
2 #include "paths.h"
3
4 std::string get_exec_path()
5 {
6   char pBuf[256];
7   size_t len = sizeof(pBuf);
8   char szTmp[32];
9
10   sprintf(szTmp, "/proc/%d/exe", getpid());
11   int bytes = readlink(szTmp, pBuf, len);
12   if (bytes > len - 1)
13     bytes = len - 1;
14   if (bytes >= 0)
15     pBuf[bytes] = '\0';
16
17   std::string exec_path = pBuf;
18   return exec_path.substr(0, exec_path.rfind(DIR_DELIM) + 1);
19 }
20
21
22 std::set<std::string> get_dm_paths() {
23   std::set<std::string> paths;
24
25   paths.insert(get_exec_path());
26
27   return paths;
28 }