Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:25:43

0001 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
0002 // Copyright Antony Polukhin, 2015-2025.
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // (See accompanying file LICENSE_1_0.txt
0006 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
0009 #define BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
0010 
0011 #include <boost/dll/config.hpp>
0012 #include <boost/dll/detail/system_error.hpp>
0013 #include <boost/predef/os.h>
0014 
0015 #ifdef BOOST_HAS_PRAGMA_ONCE
0016 # pragma once
0017 #endif
0018 
0019 #if BOOST_OS_MACOS || BOOST_OS_IOS
0020 
0021 #include <string>
0022 #include <mach-o/dyld.h>
0023 
0024 namespace boost { namespace dll { namespace detail {
0025     inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
0026         ec.clear();
0027 
0028         char path[1024];
0029         uint32_t size = sizeof(path);
0030         if (_NSGetExecutablePath(path, &size) == 0)
0031             return boost::dll::fs::path(path);
0032 
0033         std::string p;
0034         p.resize(size);
0035         if (_NSGetExecutablePath(&p[0], &size) != 0) {
0036             ec = std::make_error_code(
0037                 std::errc::bad_file_descriptor
0038             );
0039         }
0040 
0041         return boost::dll::fs::path(std::move(p));
0042     }
0043 }}} // namespace boost::dll::detail
0044 
0045 #elif BOOST_OS_SOLARIS
0046 
0047 #include <stdlib.h>
0048 namespace boost { namespace dll { namespace detail {
0049     inline boost::dll::fs::path program_location_impl(std::error_code& ec) {
0050         ec.clear();
0051 
0052         return boost::dll::fs::path(getexecname());
0053     }
0054 }}} // namespace boost::dll::detail
0055 
0056 #elif BOOST_OS_BSD_FREE
0057 
0058 #include <string>
0059 #include <sys/types.h>
0060 #include <sys/sysctl.h>
0061 #include <stdlib.h>
0062 
0063 namespace boost { namespace dll { namespace detail {
0064     inline boost::dll::fs::path program_location_impl(std::error_code& ec) {
0065         ec.clear();
0066 
0067         int mib[4];
0068         mib[0] = CTL_KERN;
0069         mib[1] = KERN_PROC;
0070         mib[2] = KERN_PROC_PATHNAME;
0071         mib[3] = -1;
0072         char path[1024];
0073         size_t size = sizeof(buf);
0074         if (sysctl(mib, 4, path, &size, nullptr, 0) == 0)
0075             return boost::dll::fs::path(path);
0076 
0077         const auto errno_snapshot = static_cast<std::errc>(errno);
0078         if (errno_snapshot != std::errc::not_enough_memory) {
0079             ec = std::make_error_code(
0080                 errno_snapshot
0081             );
0082         }
0083 
0084         std::string p;
0085         p.resize(size);
0086         if (sysctl(mib, 4, p.data(), &size, nullptr, 0) != 0) {
0087             ec = std::make_error_code(
0088                 static_cast<std::errc>(errno)
0089             );
0090         }
0091 
0092         return boost::dll::fs::path(std::move(p));
0093     }
0094 }}} // namespace boost::dll::detail
0095 
0096 
0097 
0098 #elif BOOST_OS_BSD_NET
0099 
0100 namespace boost { namespace dll { namespace detail {
0101     inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
0102         return boost::dll::fs::read_symlink("/proc/curproc/exe", ec);
0103     }
0104 }}} // namespace boost::dll::detail
0105 
0106 #elif BOOST_OS_BSD_DRAGONFLY
0107 
0108 
0109 namespace boost { namespace dll { namespace detail {
0110     inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
0111         return boost::dll::fs::read_symlink("/proc/curproc/file", ec);
0112     }
0113 }}} // namespace boost::dll::detail
0114 
0115 #elif BOOST_OS_QNX
0116 
0117 #include <fstream>
0118 #include <string> // for std::getline
0119 namespace boost { namespace dll { namespace detail {
0120     inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
0121         ec.clear();
0122 
0123         std::string path;
0124         std::ifstream ifs("/proc/self/exefile");
0125         std::getline(ifs, path);
0126 
0127         if (ifs.fail() || path.empty()) {
0128             ec = std::make_error_code(
0129                 std::errc::bad_file_descriptor
0130             );
0131         }
0132 
0133         return boost::dll::fs::path(std::move(path));
0134     }
0135 }}} // namespace boost::dll::detail
0136 
0137 #else  // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID
0138 
0139 namespace boost { namespace dll { namespace detail {
0140     inline boost::dll::fs::path program_location_impl(std::error_code &ec) {
0141         // We can not use
0142         // boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore);
0143         // because such code returns empty path.
0144 
0145         boost::dll::fs::error_code fs_errc;
0146         auto result = boost::dll::fs::read_symlink("/proc/self/exe", fs_errc);   // Linux specific
0147         ec = fs_errc;
0148         return result;
0149     }
0150 }}} // namespace boost::dll::detail
0151 
0152 #endif
0153 
0154 #endif // BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
0155