Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 15, 2024
1 parent 12d10c1 commit 429adcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
14 changes: 7 additions & 7 deletions include/boost/dll/detail/posix/path_from_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace boost { namespace dll { namespace detail {
);
}

inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path path_from_handle(void* handle, std::error_code &ec) {
handle = strip_handle(handle);

// Iterate through all images currently in memory
Expand All @@ -53,8 +53,8 @@ namespace boost { namespace dll { namespace detail {
}

boost::dll::detail::reset_dlerror();
ec = boost::dll::fs::make_error_code(
boost::dll::fs::errc::bad_file_descriptor
ec = std::make_error_code(
std::errc::bad_file_descriptor
);

return boost::dll::fs::path();
Expand All @@ -78,7 +78,7 @@ namespace boost { namespace dll { namespace detail {
// ... // Ignoring remaning parts of the structure
};

inline boost::dll::fs::path path_from_handle(const void* handle, boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path path_from_handle(const void* handle, std::error_code &ec) {
static const std::size_t work_around_b_24465209__offset = 128;
const struct soinfo* si = reinterpret_cast<const struct soinfo*>(
static_cast<const char*>(handle) + work_around_b_24465209__offset
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace boost { namespace dll { namespace detail {
};
#endif // #if BOOST_OS_QNX

inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path path_from_handle(void* handle, std::error_code &ec) {
// RTLD_DI_LINKMAP (RTLD_DI_ORIGIN returns only folder and is not suitable for this case)
// Obtain the Link_map for the handle that is specified.
// The p argument points to a Link_map pointer (Link_map
Expand All @@ -144,8 +144,8 @@ namespace boost { namespace dll { namespace detail {
#endif
if (!link_map) {
boost::dll::detail::reset_dlerror();
ec = boost::dll::fs::make_error_code(
boost::dll::fs::errc::bad_file_descriptor
ec = std::make_error_code(
std::errc::bad_file_descriptor
);

return boost::dll::fs::path();
Expand Down
27 changes: 15 additions & 12 deletions include/boost/dll/detail/posix/program_location_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <mach-o/dyld.h>

namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
ec.clear();

char path[1024];
Expand All @@ -31,8 +31,8 @@ namespace boost { namespace dll { namespace detail {

char *p = new char[size];
if (_NSGetExecutablePath(p, &size) != 0) {
ec = boost::dll::fs::make_error_code(
boost::dll::fs::errc::bad_file_descriptor
ec = std::make_error_code(
std::errc::bad_file_descriptor
);
}

Expand All @@ -46,7 +46,7 @@ namespace boost { namespace dll { namespace detail {

#include <stdlib.h>
namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) {
inline boost::dll::fs::path program_location_impl(std::error_code& ec) {
ec.clear();

return boost::dll::fs::path(getexecname());
Expand All @@ -60,7 +60,7 @@ namespace boost { namespace dll { namespace detail {
#include <stdlib.h>

namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) {
inline boost::dll::fs::path program_location_impl(std::error_code& ec) {
ec.clear();

int mib[4];
Expand All @@ -81,7 +81,7 @@ namespace boost { namespace dll { namespace detail {
#elif BOOST_OS_BSD_NET

namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
return boost::dll::fs::read_symlink("/proc/curproc/exe", ec);
}
}}} // namespace boost::dll::detail
Expand All @@ -90,7 +90,7 @@ namespace boost { namespace dll { namespace detail {


namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
return boost::dll::fs::read_symlink("/proc/curproc/file", ec);
}
}}} // namespace boost::dll::detail
Expand All @@ -100,16 +100,16 @@ namespace boost { namespace dll { namespace detail {
#include <fstream>
#include <string> // for std::getline
namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
ec.clear();

std::string s;
std::ifstream ifs("/proc/self/exefile");
std::getline(ifs, s);

if (ifs.fail() || s.empty()) {
ec = boost::dll::fs::make_error_code(
boost::dll::fs::errc::bad_file_descriptor
ec = std::make_error_code(
std::errc::bad_file_descriptor
);
}

Expand All @@ -120,12 +120,15 @@ namespace boost { namespace dll { namespace detail {
#else // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID

namespace boost { namespace dll { namespace detail {
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
// We can not use
// boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore);
// because such code returns empty path.

return boost::dll::fs::read_symlink("/proc/self/exe", ec); // Linux specific
boost::dll::fs::error_code fs_errc;
auto result = boost::dll::fs::read_symlink("/proc/self/exe", fs_errc); // Linux specific
ec = fs_errc;
return result;
}
}}} // namespace boost::dll::detail

Expand Down

0 comments on commit 429adcc

Please sign in to comment.