Lots of changes to make glest binary more portable on linux.

This commit is contained in:
Jammyjamjamman
2019-04-12 21:28:19 +01:00
parent 629229a6bf
commit 35b08573f8
9 changed files with 107 additions and 61 deletions

View File

@@ -32,6 +32,7 @@
#include <io.h> // for open()
#else
#include <unistd.h>
#include <limits.h>
#endif
#include <sys/stat.h> // for open()
@@ -874,5 +875,45 @@ namespace Shared {
return 0;
}
}
#ifdef __linux__
std::string getExecPath() {
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len != -1) {
buff[len] = '\0';
return std::string(buff);
}
/* handle error condition */
return std::string("");
}
#endif // __linux__
void eraseSubStr(std::string & mainStr, const std::string & toErase)
{
// Search for the substring in string
size_t pos = mainStr.find(toErase);
if (pos != std::string::npos)
{
// If found then erase it from string
mainStr.erase(pos, toErase.length());
}
}
#if defined(DATADIR) && defined(BINDIR)
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
}
} //end namespace