23 # include "msvc/config.h"
24 #elif defined(HAVE_CONFIG_H)
41 #if defined(__native_client__) || defined(__SWITCH__)
42 #define realpath(N, R) strcpy(R, N)
47 #define realpath(N, R) _fullpath((R), (N), _MAX_PATH)
50 #if defined __OpenBSD__
58 #include <sys/types.h>
63 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
66 #include <SDL_system.h>
71 #if defined(__native_client__) || defined(__SWITCH__)
73 #define SSIZE_MAX INT_MAX
86 #if defined(__GLIBC__)
87 if (str.find(
"(unreachable)") != std::string::npos)
92 if (str.size() > SSIZE_MAX / 10)
96 #if defined(__OpenBSD__) || defined(__ANDROID__) || \
97 defined(__native_client__) || defined(__SWITCH__)
98 char *realPath =
reinterpret_cast<char*
>(calloc(PATH_MAX,
sizeof(
char)));
101 realpath(str.c_str(), realPath);
105 char *realPath = realpath(str.c_str(),
nullptr);
106 if (realPath ==
nullptr)
111 std::string path = realPath;
125 return path.find(
"../") == std::string::npos
126 && path.find(
"..\\") == std::string::npos
127 && path.find(
"/..") == std::string::npos
128 && path.find(
"\\..") == std::string::npos
129 && path.find(
"(unreachable)") == std::string::npos;
135 std::string path2 = path;
160 size_t pos2 = str.rfind(
'/');
161 const size_t pos3 = str.rfind(
'\\');
162 if (pos3 != std::string::npos)
164 if (pos2 == std::string::npos || pos3 > pos2)
167 if (pos2 != std::string::npos)
168 return str.substr(0, pos2);
175 return "manaplus.exe";
178 #elif defined(__APPLE__)
181 return "manaplus.exe";
184 #elif defined __linux__ || defined __linux
189 const ssize_t sz = readlink(
"/proc/self/exe", buf, 256);
190 if (sz > 0 && sz < 256)
210 std::string dir = getSpecialFolderLocation(CSIDL_MYPICTURES);
212 dir = getSpecialFolderLocation(CSIDL_DESKTOP);
214 #elif defined USE_X11
215 char *xdg = getenv(
"XDG_CONFIG_HOME");
220 ".config/user-dirs.dirs");
224 file =
pathJoin(xdg,
"user-dirs.dirs");
233 std::string str = *it;
236 str = str.substr(0, str.size() - 1);
254 #if defined(UNITTESTS) && defined(UNITESTSDIR)
255 std::string dir = UNITESTSDIR;
261 return getSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
262 #elif defined(__SWITCH__)
265 const char *path = getenv(
"HOME");
268 const uid_t uid = getuid();
269 const passwd *
const pw = getpwuid(uid);
271 pw->pw_dir !=
nullptr)
278 std::string dir = path;
287 std::string getSdStoragePath()
289 return getenv(
"DATADIR2");
#define reportAlways(...)
const char * dirSeparator
#define FOR_EACH(type, iter, array)
bool loadTextFileLocal(const std::string &fileName, StringVect &lines)
bool existsLocal(const std::string &path)
const char * getBaseDir()
const char * getUserDir()
std::string & fixDirSeparators(std::string &str)
std::string getRealPath(const std::string &str)
std::string getPicturesDir()
std::string getPackageDir()
std::string getSelfName()
bool checkPath(const std::string &path)
void setPackageDir(const std::string &dir)
std::string getHomePath()
bool isRealPath(const std::string &str)
void prepareFsPath(std::string &path)
std::string removeLast(const std::string &str)
void sanitizePath(std::string &path)
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
bool findCutFirst(std::string &str1, const std::string &str2)
bool findLast(const std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
StringVect::const_iterator StringVectCIter
std::vector< std::string > StringVect