[skip ci] Solaris getexecname() returns argv[0]

`argv[0]`/`getexexname()` are not always absolute paths by default and can be modified to anything the developer wants them to be.

Consider using `readSymLink("/proc/self/path/a.out")` instead and `getexecname()` as the fallback, since the symlink will always be the correct absolute path (unless /proc is ot mounted, but it is by default on Solaris and Illumos platforms).
This commit is contained in:
Samuel Venable 2022-11-27 21:19:41 -05:00 committed by Ryan C. Gordon
parent f3c466ec1e
commit 4f5e9fd5bd
1 changed files with 14 additions and 11 deletions

View File

@ -199,16 +199,6 @@ SDL_GetBasePath(void)
SDL_free(cmdline);
}
#endif
#if defined(__SOLARIS__)
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
retval = SDL_strdup(path);
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
}
#endif
/* is a Linux-style /proc filesystem available? */
if (retval == NULL && (access("/proc", F_OK) == 0)) {
@ -219,6 +209,8 @@ SDL_GetBasePath(void)
retval = readSymLink("/proc/curproc/file");
#elif defined(__NETBSD__)
retval = readSymLink("/proc/curproc/exe");
#elif defined(__SOLARIS__)
retval = readSymLink("/proc/self/path/a.out");
#else
retval = readSymLink("/proc/self/exe"); /* linux. */
if (retval == NULL) {
@ -233,7 +225,18 @@ SDL_GetBasePath(void)
}
#endif
}
#if defined(__SOLARIS__)
else {
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
retval = SDL_strdup(path);
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
}
}
#endif
/* If we had access to argv[0] here, we could check it for a path,
or troll through $PATH looking for it, too. */