From 7229b18aacd79ddbe11934a3c28155a6d6fe92a4 Mon Sep 17 00:00:00 2001 From: Genxster1998 Date: Mon, 25 Nov 2024 22:35:03 +0530 Subject: [PATCH] Add method to get executable path on MacOS Signed-off-by: Romain Vimont --- app/src/sys/unix/file.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/sys/unix/file.c b/app/src/sys/unix/file.c index 9c3f733318..60c806bb27 100644 --- a/app/src/sys/unix/file.c +++ b/app/src/sys/unix/file.c @@ -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 }