#include <stdlib.h> // for getenv, realpath, ... #include <string.h> // for snprintf #include <unistd.h> // for access, readlink, ...
#ifdefined(__APPLE__) && defined(__MACH__) // Workaround: TRUE / FALSE are also defined by the macOS Mach-O headers #define ENUM_DYLD_BOOL #include <mach-o/dyld.h> #endif
staticvoid SetupGAPLocation(constchar * argv0, char * GAPExecLocation)
{ // In the code below, we keep resetting locBuf, as some of the methods we // try do not promise to leave the buffer empty on a failed return. char locBuf[GAP_PATH_MAX] = "";
Int4 length = 0;
#ifdefined(__APPLE__) && defined(__MACH__)
uint32_t len = sizeof(locBuf); if (_NSGetExecutablePath(locBuf, &len) != 0) {
*locBuf = 0; // reset buffer after error
} #endif
// try Linux procfs if (!*locBuf) {
ssize_t ret = readlink("/proc/self/exe", locBuf, sizeof(locBuf)); if (ret < 0)
*locBuf = 0; // reset buffer after error
}
// try FreeBSD / DragonFly BSD procfs if (!*locBuf) {
ssize_t ret = readlink("/proc/curproc/file", locBuf, sizeof(locBuf)); if (ret < 0)
*locBuf = 0; // reset buffer after error
}
// try NetBSD procfs if (!*locBuf) {
ssize_t ret = readlink("/proc/curproc/exe", locBuf, sizeof(locBuf)); if (ret < 0)
*locBuf = 0; // reset buffer after error
}
// if we are still failing, go and search the path if (!*locBuf) {
find_yourself(argv0, locBuf, GAP_PATH_MAX);
}
// resolve symlinks (if present) if (!realpath(locBuf, GAPExecLocation))
*GAPExecLocation = 0; // reset buffer after error
// now strip the executable name off
length = strlen(GAPExecLocation); while (length > 0 && GAPExecLocation[length] != '/') {
GAPExecLocation[length] = 0;
length--;
}
}
/**************************************************************************** ** *FSySetInitialGapRootPaths(<string>).....settherootdirectories ** **SetupGAP'sinitialrootpaths,basedonthelocationofthe **GAPexecutable.
*/ staticvoid SySetInitialGapRootPaths(constchar * GAPExecLocation)
{ if (GAPExecLocation[0] != 0) { // GAPExecLocation might be a subdirectory of GAP root, // so we will go and search for the true GAP root. // We try stepping back up to two levels. char pathbuf[GAP_PATH_MAX]; char initgbuf[GAP_PATH_MAX];
strxcpy(pathbuf, GAPExecLocation, sizeof(pathbuf)); for (Int i = 0; i < 3; ++i) {
strxcpy(initgbuf, pathbuf, sizeof(initgbuf));
strxcat(initgbuf, "lib/init.g", sizeof(initgbuf));
if (SyIsReadableFile(initgbuf) == 0) {
gap_strlcpy(SyDefaultRootPath, pathbuf, sizeof(SyDefaultRootPath)); // escape from loop return;
} // try up a directory level
strxcat(pathbuf, "../", sizeof(pathbuf));
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.