mirror of
https://github.com/glest/glest-source.git
synced 2025-08-25 09:10:49 +02:00
Lots of changes to make glest binary more portable on linux.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user