X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fpaths.cpp;h=b7a8374f0ae6e49fdc138bfcd02d741ffe4e1fcb;hb=4fce641cc077d18f972e250d2fe3be5067618127;hp=ae05f3b661d400ac988201c429b4ee1c2889c885;hpb=c4a0774d367b5e8ff7a2aeebf1bbe4386621b51f;p=dungeon-master.git diff --git a/src/paths.cpp b/src/paths.cpp index ae05f3b..b7a8374 100644 --- a/src/paths.cpp +++ b/src/paths.cpp @@ -1,28 +1,52 @@ +/* Dungeon Master --- RPG Adventure Generator + Copyright © 2019 Javier Sancho + + Dungeon Master is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Dungeon Master is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Dungeon Master. If not, see . +*/ + #include #include "paths.h" -std::string get_exec_path() +std::string +get_exec_path () { char pBuf[256]; - size_t len = sizeof(pBuf); + size_t len = sizeof (pBuf); char szTmp[32]; - sprintf(szTmp, "/proc/%d/exe", getpid()); - int bytes = readlink(szTmp, pBuf, len); + 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); + return exec_path.substr (0, exec_path.rfind (PATH_DELIM) + 1); } +std::string +get_home_path () +{ + return (std::string) getenv ("HOME") + PATH_DELIM + "." + PROGRAM_NAME; +} -std::set get_dm_paths() { +std::set +get_dmaster_paths () { std::set paths; - - paths.insert(get_exec_path()); - + paths.insert (get_exec_path ()); + paths.insert (DATA_PATH); + paths.insert (get_home_path ()); return paths; }