Skip to content

Commit

Permalink
i#58 MacOS: get_application_name()
Browse files Browse the repository at this point in the history
Acquire the app name from the stack on MacOS where the kernel stores it (on
Linux we read /proc/self/exe but that does not exist on Mac).

SVN-Revision: 2422
  • Loading branch information
derekbruening committed Dec 5, 2013
1 parent 112fe5b commit 6726ebc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/unix/os.c
Expand Up @@ -786,7 +786,22 @@ get_application_name_helper(bool ignore_cache, bool full_path)
strncpy(executable_path, read_proc_self_exe(ignore_cache),
BUFFER_SIZE_ELEMENTS(executable_path));
#else
ASSERT_NOT_IMPLEMENTED(false);
/* OSX kernel puts full app path and as-executed path below envp */
const char *c = *our_environ;
do {
c--;
} while (*c == '\0');
/* Now skip the specified path which might be relative */
while (*c != '\0')
c--;
do {
c--;
} while (*c == '\0');
/* Now find the front of the absolute path */
while (*c != '\0')
c--;
c++; /* Skip the null */
strncpy(executable_path, c, BUFFER_SIZE_ELEMENTS(executable_path));
#endif
NULL_TERMINATE_BUFFER(executable_path);
/* FIXME: Fall back on /proc/self/cmdline and maybe argv[0] from
Expand Down

0 comments on commit 6726ebc

Please sign in to comment.