(OpenBSD) Exe Path: Use PWD instead of CWD and use CWD as fallback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index e25229d..67f908d 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -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,13 +172,28 @@ 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 (realpath(exe, realpathbuf) != NULL) {
- retval = realpathbuf;
+ 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]) {