Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Aug 30, 2024
1 parent cb65ab5 commit a1a496e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/test_util/executable_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#include "executable_path.hpp"

#include <array>
#include <stdexcept>
#include <string>
#include <system_error>

#if defined(_WIN32)
#include <array>

#include "util/platform.hpp"

namespace test_util {
Expand All @@ -37,39 +37,38 @@ std::string get_executable_path() {
if (size) {
return std::string(buffer.data(), size);
}
throw std::runtime_error("Could not get executable path");
throw std::system_error(std::make_error_code(std::errc::no_such_file_or_directory),
"Could not get executable path");
}
} // namespace test_util

#elif defined(__APPLE__)
#include <mach-o/dyld.h>

#include <climits>

namespace test_util {
std::string get_executable_path() {
std::array<char, PATH_MAX> buffer{};
uint32_t size = buffer.size();
if (::_NSGetExecutablePath(buffer.data(), &size) == 0) {
return std::string(buffer.data());
}
throw std::runtime_error("Could not get executable path");
throw std::system_error(std::make_error_code(std::errc::no_such_file_or_directory),
"Could not get executable path");
}
} // namespace test_util

#elif defined(__linux__)
#include <unistd.h>

#include <climits>

namespace test_util {
std::string get_executable_path() {
std::array<char, PATH_MAX> buffer{};
ssize_t size = ::readlink("/proc/self/exe", buffer.data(), buffer.size());
if (size != -1) {
return std::string(buffer.data(), size);
}
throw std::runtime_error("Could not get executable path");
throw std::system_error(std::make_error_code(std::errc::no_such_file_or_directory),
"Could not get executable path");
}
} // namespace test_util

Expand Down

0 comments on commit a1a496e

Please sign in to comment.