File indexing completed on 2025-01-18 09:50:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP
0012 #define BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP
0013
0014 #include <boost/process/v2/detail/config.hpp>
0015 #include <boost/process/v2/detail/last_error.hpp>
0016 #include <boost/process/v2/environment.hpp>
0017 #include <boost/process/v2/cstring_ref.hpp>
0018
0019 #include <unistd.h>
0020 #include <cstring>
0021
0022
0023 BOOST_PROCESS_V2_BEGIN_NAMESPACE
0024
0025 namespace environment
0026 {
0027 namespace detail
0028 {
0029
0030 basic_cstring_ref<char_type, value_char_traits<char>> get(
0031 basic_cstring_ref<char_type, key_char_traits<char_type>> key,
0032 error_code & ec)
0033 {
0034 auto res = ::getenv(key.c_str());
0035 if (res == nullptr)
0036 {
0037 BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOENT, system_category())
0038 return {};
0039 }
0040 return res;
0041 }
0042
0043 void set(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
0044 basic_cstring_ref<char_type, value_char_traits<char_type>> value,
0045 error_code & ec)
0046 {
0047 if (::setenv(key.c_str(), value.c_str(), true))
0048 BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
0049 }
0050
0051 void unset(basic_cstring_ref<char_type, key_char_traits<char_type>> key, error_code & ec)
0052 {
0053 if (::unsetenv(key.c_str()))
0054 BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
0055 }
0056
0057
0058 native_handle_type load_native_handle() { return ::environ; }
0059
0060
0061 native_iterator next(native_iterator nh)
0062 {
0063 return nh + 1;
0064 }
0065
0066 native_iterator find_end(native_handle_type nh)
0067 {
0068 while (*nh != nullptr)
0069 nh++;
0070 return nh;
0071 }
0072 bool is_executable(const filesystem::path & p, error_code & ec)
0073 {
0074 return filesystem::is_regular_file(p, ec) && (::access(p.c_str(), X_OK) == 0);
0075 }
0076
0077 }
0078 }
0079 BOOST_PROCESS_V2_END_NAMESPACE
0080
0081 #endif