]> git.jsancho.org Git - dungeon-master.git/blob - src/paths.cpp
register scene generators
[dungeon-master.git] / src / paths.cpp
1 /* Dungeon Master --- RPG Adventure Generator
2    Copyright © 2019 Javier Sancho <jsf@jsancho.org>
3
4    Dungeon Master is free software; you can redistribute it and/or modify it
5    under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    Dungeon Master is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <unistd.h>
19 #include "paths.h"
20
21 std::string
22 get_exec_path ()
23 {
24   char pBuf[256];
25   size_t len = sizeof (pBuf);
26   char szTmp[32];
27
28   sprintf (szTmp, "/proc/%d/exe", getpid ());
29   int bytes = readlink (szTmp, pBuf, len);
30   if (bytes > len - 1)
31     bytes = len - 1;
32   if (bytes >= 0)
33     pBuf[bytes] = '\0';
34
35   std::string exec_path = pBuf;
36   return exec_path.substr (0, exec_path.rfind (PATH_DELIM) + 1);
37 }
38
39 std::string
40 get_home_path ()
41 {
42   return (std::string) getenv ("HOME") + PATH_DELIM + "." + PROGRAM_NAME;
43 }
44
45 std::set<std::string>
46 get_dmaster_paths () {
47   std::set<std::string> paths;
48   paths.insert (get_exec_path ());
49   paths.insert (DATA_PATH);
50   paths.insert (get_home_path ());
51   return paths;
52 }