// // process/this_process/detail/environment_posix.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021 Klemens D. Morgenstern (klemens dot morgenstern at gmx dot net) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP #define BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP #include #include #include #include #include #include BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace environment { namespace detail { basic_cstring_ref> get( basic_cstring_ref> key, error_code & ec) { auto res = ::getenv(key.c_str()); if (res == nullptr) { ec.assign(ENOENT, system_category()); return {}; } return res; } void set(basic_cstring_ref> key, basic_cstring_ref> value, error_code & ec) { if (::setenv(key.c_str(), value.c_str(), true)) ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); } void unset(basic_cstring_ref> key, error_code & ec) { if (::unsetenv(key.c_str())) ec = ::BOOST_PROCESS_V2_NAMESPACE::detail::get_last_error(); } native_handle_type load_native_handle() { return ::environ; } native_iterator next(native_iterator nh) { return nh + 1; } native_iterator find_end(native_handle_type nh) { while (*nh != nullptr) nh++; return nh; } bool is_executable(const filesystem::path & p, error_code & ec) { return filesystem::is_regular_file(p, ec) && (::access(p.c_str(), X_OK) == 0); } } } BOOST_PROCESS_V2_END_NAMESPACE #endif //BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_WIN_HPP