]> git.jsancho.org Git - dungeon-master.git/blob - src/paths.cpp
Some things
[dungeon-master.git] / src / paths.cpp
1 /* Dungeon Master --- Adventure generator for GNU Guile
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 Haunt.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <unistd.h>
19 #include "paths.h"
20
21 std::string get_exec_path()
22 {
23   char pBuf[256];
24   size_t len = sizeof(pBuf);
25   char szTmp[32];
26
27   sprintf(szTmp, "/proc/%d/exe", getpid());
28   int bytes = readlink(szTmp, pBuf, len);
29   if (bytes > len - 1)
30     bytes = len - 1;
31   if (bytes >= 0)
32     pBuf[bytes] = '\0';
33
34   std::string exec_path = pBuf;
35   return exec_path.substr(0, exec_path.rfind(PATH_DELIM) + 1);
36 }
37
38 std::string get_home_path()
39 {
40   return (std::string)getenv("HOME") + PATH_DELIM + "." + PROGRAM_NAME;
41 }
42
43 std::set<std::string> get_data_paths() {
44   std::set<std::string> paths;
45   paths.insert(get_exec_path());
46   paths.insert(DATA_PATH);
47   paths.insert(get_home_path());
48   return paths;
49 }