Skip to content

Commit

Permalink
Add method to get executable path on MacOS
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
Genxster1998 authored and rom1v committed Nov 28, 2024
1 parent 017a367 commit 7229b18
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/src/sys/unix/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ sc_file_get_executable_path(void) {
}
buf[len] = '\0';
return strdup(buf);
#elif defined(__APPLE__)
char buf[PATH_MAX];
uint32_t bufsize = PATH_MAX;
if (_NSGetExecutablePath(buf, &bufsize) != 0) {
LOGE("Executable path buffer too small; need %u bytes", bufsize);
return NULL;
}
return realpath(buf, NULL);
#else
// in practice, we only need this feature for portable builds, only used on
// Windows, so we don't care implementing it for every platform
// (it's useful to have a working version on Linux for debugging though)
return NULL;
// "_" is often used to store the full path of the command being executed
char *path = getenv("_");
if (!path) {
LOGE("Could not determine executable path");
return NULL;
}
return strdup(path);
#endif
}

Expand Down

0 comments on commit 7229b18

Please sign in to comment.