]> git.jsancho.org Git - dungeon-master.git/blobdiff - src/paths.cpp
Search paths for mods and games
[dungeon-master.git] / src / paths.cpp
diff --git a/src/paths.cpp b/src/paths.cpp
new file mode 100644 (file)
index 0000000..ae05f3b
--- /dev/null
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include "paths.h"
+
+std::string get_exec_path()
+{
+  char pBuf[256];
+  size_t len = sizeof(pBuf);
+  char szTmp[32];
+
+  sprintf(szTmp, "/proc/%d/exe", getpid());
+  int bytes = readlink(szTmp, pBuf, len);
+  if (bytes > len - 1)
+    bytes = len - 1;
+  if (bytes >= 0)
+    pBuf[bytes] = '\0';
+
+  std::string exec_path = pBuf;
+  return exec_path.substr(0, exec_path.rfind(DIR_DELIM) + 1);
+}
+
+
+std::set<std::string> get_dm_paths() {
+  std::set<std::string> paths;
+
+  paths.insert(get_exec_path());
+
+  return paths;
+}