Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:43

0001 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
0002 // Copyright Antony Polukhin, 2015-2023.
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 <mach-o/dyld.h>
0022 
0023 namespace boost { namespace dll { namespace detail {
0024     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0025         ec.clear();
0026 
0027         char path[1024];
0028         uint32_t size = sizeof(path);
0029         if (_NSGetExecutablePath(path, &size) == 0)
0030             return boost::dll::fs::path(path);
0031 
0032         char *p = new char[size];
0033         if (_NSGetExecutablePath(p, &size) != 0) {
0034             ec = boost::dll::fs::make_error_code(
0035                 boost::dll::fs::errc::bad_file_descriptor
0036             );
0037         }
0038 
0039         boost::dll::fs::path ret(p);
0040         delete[] p;
0041         return ret;
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(boost::dll::fs::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 <sys/types.h>
0059 #include <sys/sysctl.h>
0060 #include <stdlib.h>
0061 
0062 namespace boost { namespace dll { namespace detail {
0063     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) {
0064         ec.clear();
0065 
0066         int mib[4];
0067         mib[0] = CTL_KERN;
0068         mib[1] = KERN_PROC;
0069         mib[2] = KERN_PROC_PATHNAME;
0070         mib[3] = -1;
0071         char buf[10240];
0072         size_t cb = sizeof(buf);
0073         sysctl(mib, 4, buf, &cb, NULL, 0);
0074 
0075         return boost::dll::fs::path(buf);
0076     }
0077 }}} // namespace boost::dll::detail
0078 
0079 
0080 
0081 #elif BOOST_OS_BSD_NET
0082 
0083 namespace boost { namespace dll { namespace detail {
0084     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0085         return boost::dll::fs::read_symlink("/proc/curproc/exe", ec);
0086     }
0087 }}} // namespace boost::dll::detail
0088 
0089 #elif BOOST_OS_BSD_DRAGONFLY
0090 
0091 
0092 namespace boost { namespace dll { namespace detail {
0093     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0094         return boost::dll::fs::read_symlink("/proc/curproc/file", ec);
0095     }
0096 }}} // namespace boost::dll::detail
0097 
0098 #elif BOOST_OS_QNX
0099 
0100 #include <fstream>
0101 #include <string> // for std::getline
0102 namespace boost { namespace dll { namespace detail {
0103     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0104         ec.clear();
0105 
0106         std::string s;
0107         std::ifstream ifs("/proc/self/exefile");
0108         std::getline(ifs, s);
0109 
0110         if (ifs.fail() || s.empty()) {
0111             ec = boost::dll::fs::make_error_code(
0112                 boost::dll::fs::errc::bad_file_descriptor
0113             );
0114         }
0115 
0116         return boost::dll::fs::path(s);
0117     }
0118 }}} // namespace boost::dll::detail
0119 
0120 #else  // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID
0121 
0122 namespace boost { namespace dll { namespace detail {
0123     inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0124         // We can not use
0125         // boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore);
0126         // because such code returns empty path.
0127 
0128         return boost::dll::fs::read_symlink("/proc/self/exe", ec);   // Linux specific
0129     }
0130 }}} // namespace boost::dll::detail
0131 
0132 #endif
0133 
0134 #endif // BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
0135