Skip to content

Commit

Permalink
better way of detecting current exe path on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Jan 4, 2024
1 parent 3dad0bd commit 9c14177
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/apps/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <base/pipeline.h>

#ifdef LUISA_PLATFORM_WINDOWS
#include <windows.h>
[[nodiscard]] auto get_current_exe_path() noexcept {
constexpr auto max_path_length = static_cast<size_t>(4096);
std::filesystem::path::value_type path[max_path_length] = {};
Expand All @@ -27,8 +28,17 @@
return std::filesystem::canonical(path).string();
}
#else
#include <libproc.h>
#include <unistd.h>
[[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

Expand Down

0 comments on commit 9c14177

Please sign in to comment.