mirror of https://github.com/encounter/SDL.git
(OpenBSD) Exe Path: Use PWD instead of CWD and use CWD as fallback
This commit is contained in:
parent
883409ea07
commit
24b3efd08d
|
@ -150,7 +150,7 @@ SDL_GetBasePath(void)
|
|||
}
|
||||
#endif
|
||||
#if defined(__OPENBSD__)
|
||||
/* Please note that this will fail if the process was launched with a relative path and the cwd has changed, or argv is altered. So don't do that. Or add a new sysctl to OpenBSD. */
|
||||
/* Please note that this will fail if the process was launched with a relative path and $PWD + the cwd have changed, or argv is altered. So don't do that. Or add a new sysctl to OpenBSD. */
|
||||
char **cmdline;
|
||||
size_t len;
|
||||
const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
|
||||
|
@ -172,14 +172,29 @@ SDL_GetBasePath(void)
|
|||
sysctl(mib, 4, cmdline, &len, NULL, 0);
|
||||
|
||||
exe = cmdline[0];
|
||||
char *pwddst = NULL;
|
||||
if (SDL_strchr(exe, '/') == NULL) { /* not a relative or absolute path, check $PATH for it */
|
||||
exe = search_path_for_binary(cmdline[0]);
|
||||
} else {
|
||||
if (exe && *exe == '.') {
|
||||
const char *pwd = SDL_getenv("PWD");
|
||||
if (pwd && *pwd) {
|
||||
SDL_asprintf(&pwddst, "%s/%s", pwd, exe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exe) {
|
||||
if (pwddst == NULL) {
|
||||
if (realpath(exe, realpathbuf) != NULL) {
|
||||
retval = realpathbuf;
|
||||
}
|
||||
} else {
|
||||
if (realpath(pwddst, realpathbuf) != NULL) {
|
||||
retval = realpathbuf;
|
||||
}
|
||||
SDL_free(pwddst);
|
||||
}
|
||||
|
||||
if (exe != cmdline[0]) {
|
||||
SDL_free(exe);
|
||||
|
|
Loading…
Reference in New Issue