unix: Better base dir calculation for Solaris.

This idea came from https://github.com/libsdl-org/SDL/pull/6681 (thanks!)

(cherry picked from commit 9266e773d3)
This commit is contained in:
Ryan C. Gordon 2022-11-27 21:45:07 -05:00
parent eb3383b532
commit bfa7997c67
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 10 additions and 6 deletions

View File

@ -261,12 +261,6 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1) if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1)
retval = __PHYSFS_strdup(fullpath); retval = __PHYSFS_strdup(fullpath);
} }
#elif defined(PHYSFS_PLATFORM_SOLARIS)
{
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */
retval = __PHYSFS_strdup(path);
}
#endif #endif
/* If there's a Linux-like /proc filesystem, you can get the full path to /* If there's a Linux-like /proc filesystem, you can get the full path to
@ -278,6 +272,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
retval = readSymLink("/proc/self/exe"); retval = readSymLink("/proc/self/exe");
if (!retval) retval = readSymLink("/proc/curproc/file"); if (!retval) retval = readSymLink("/proc/curproc/file");
if (!retval) retval = readSymLink("/proc/curproc/exe"); if (!retval) retval = readSymLink("/proc/curproc/exe");
if (!retval) retval = readSymLink("/proc/self/path/a.out");
if (retval == NULL) if (retval == NULL)
{ {
/* older kernels don't have /proc/self ... try PID version... */ /* older kernels don't have /proc/self ... try PID version... */
@ -289,6 +284,15 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
} /* if */ } /* if */
} /* if */ } /* if */
#if defined(PHYSFS_PLATFORM_SOLARIS)
if (!retval) /* try getexecname() if /proc didn't pan out. This may not be an absolute path! */
{
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */
retval = __PHYSFS_strdup(path);
} /* if */
#endif
if (retval != NULL) /* chop off filename. */ if (retval != NULL) /* chop off filename. */
{ {
char *ptr = strrchr(retval, '/'); char *ptr = strrchr(retval, '/');