Skip to content

Commit 7b76025

Browse files
Samuel Venablesezero
Samuel Venable
authored andcommitted
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). (cherry picked from commit 4f5e9fd)
1 parent e2465e3 commit 7b76025

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/filesystem/unix/SDL_sysfilesystem.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,6 @@ SDL_GetBasePath(void)
193193
SDL_free(cmdline);
194194
}
195195
#endif
196-
#if defined(__SOLARIS__)
197-
const char *path = getexecname();
198-
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
199-
retval = SDL_strdup(path);
200-
if (!retval) {
201-
SDL_OutOfMemory();
202-
return NULL;
203-
}
204-
}
205-
#endif
206196

207197
/* is a Linux-style /proc filesystem available? */
208198
if (!retval && (access("/proc", F_OK) == 0)) {
@@ -213,6 +203,8 @@ SDL_GetBasePath(void)
213203
retval = readSymLink("/proc/curproc/file");
214204
#elif defined(__NETBSD__)
215205
retval = readSymLink("/proc/curproc/exe");
206+
#elif defined(__SOLARIS__)
207+
retval = readSymLink("/proc/self/path/a.out");
216208
#elif defined(__QNXNTO__)
217209
retval = SDL_LoadFile("/proc/self/exefile", NULL);
218210
#else
@@ -230,6 +222,19 @@ SDL_GetBasePath(void)
230222
#endif
231223
}
232224

225+
#if defined(__SOLARIS__) /* try this as a fallback if /proc didn't pan out */
226+
if (!retval) {
227+
const char *path = getexecname();
228+
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
229+
retval = SDL_strdup(path);
230+
if (!retval) {
231+
SDL_OutOfMemory();
232+
return NULL;
233+
}
234+
}
235+
}
236+
#endif
237+
233238
/* If we had access to argv[0] here, we could check it for a path,
234239
or troll through $PATH looking for it, too. */
235240

0 commit comments

Comments
 (0)