From 9c14177af07d9757bac7c975a66f090bffdc01dd Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Thu, 4 Jan 2024 14:56:06 +0800 Subject: [PATCH] better way of detecting current exe path on macOS --- src/apps/cli.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/apps/cli.cpp b/src/apps/cli.cpp index 61af74b2..a5413334 100644 --- a/src/apps/cli.cpp +++ b/src/apps/cli.cpp @@ -14,6 +14,7 @@ #include #ifdef LUISA_PLATFORM_WINDOWS +#include [[nodiscard]] auto get_current_exe_path() noexcept { constexpr auto max_path_length = static_cast(4096); std::filesystem::path::value_type path[max_path_length] = {}; @@ -27,8 +28,17 @@ return std::filesystem::canonical(path).string(); } #else +#include +#include [[nodiscard]] auto get_current_exe_path() noexcept { - LUISA_NOT_IMPLEMENTED();// TODO + char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; + auto pid = getpid(); + if (proc_pidpath(pid, pathbuf, sizeof(pathbuf)) <= 0) { + LUISA_ERROR_WITH_LOCATION( + "Failed to get current executable path (PID = {}): {}.", + pid, strerror(errno)); + } + return std::filesystem::canonical(pathbuf).string(); } #endif