File indexing completed on 2025-01-18 09:30:43
0001
0002
0003
0004
0005
0006
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 }}}
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 }}}
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 }}}
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 }}}
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 }}}
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 }}}
0119
0120 #else
0121
0122 namespace boost { namespace dll { namespace detail {
0123 inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
0124
0125
0126
0127
0128 return boost::dll::fs::read_symlink("/proc/self/exe", ec);
0129 }
0130 }}}
0131
0132 #endif
0133
0134 #endif
0135