diff --git a/source/game/global/config.cpp b/source/game/global/config.cpp index fecaa9e71..5b3cd7624 100644 --- a/source/game/global/config.cpp +++ b/source/game/global/config.cpp @@ -264,7 +264,7 @@ namespace Game { #endif -#if defined(DATADIR) && defined(BINDIR) +#if defined(DATADIR) && defined(BINDIR) && defined(__unix__) if ((foundPath == false)) { currentpath = getDatPath(); foundPath = tryCustomPath(cfgType, fileName, currentpath); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index b3c17975a..952d8baf8 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -53,7 +53,7 @@ namespace Shared { namespace Util { string Properties::applicationPath = ""; -#if defined(DATADIR) && defined(BINDIR) +#if defined(DATADIR) && defined(BINDIR) && defined(__unix__) string Properties::applicationDataPath = getDatPath(); #else string Properties::applicationDataPath = ""; diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 687337da4..5c7f83515 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -876,10 +876,15 @@ namespace Shared { } } -#ifdef __linux__ +#ifdef __unix__ std::string getExecPath() { char buff[PATH_MAX]; +#ifdef __linux__ ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1); +#else + // e.g. for FreeBSD with procfs installed. + ssize_t len = ::readlink("/proc/curproc/file", buff, sizeof(buff)-1); +#endif // __linux__ if (len != -1) { buff[len] = '\0'; return std::string(buff); @@ -901,17 +906,12 @@ namespace Shared { } -#if defined(DATADIR) && defined(BINDIR) +#if defined(DATADIR) && defined(BINDIR) && defined(__unix__) string getDatPath() { string curPath = getExecPath(); - printf("\n binary Path: %s", curPath.c_str()); const string subBinPath = endPathWithSlash(formatPath(TOSTRING(BINDIR))) + "glest"; - printf("\n binary Path: %s", subBinPath.c_str()); eraseSubStr(curPath, subBinPath); - printf("\n path now: %s", curPath.c_str()); string datPath = curPath + endPathWithSlash(TOSTRING(DATADIR)); - printf("\n what is this???: %s", TOSTRING(DATADIR)); - printf("\n data path: %s", datPath.c_str()); return datPath; } #endif