environment_posix.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // process/environment/detail/environment_posix.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2021 Klemens D. Morgenstern (klemens dot morgenstern at gmx dot net)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_POSIX_HPP
  11. #define BOOST_PROCESS_V2_DETAIL_ENVIRONMENT_POSIX_HPP
  12. #include <boost/process/v2/detail/config.hpp>
  13. #include <boost/process/v2/cstring_ref.hpp>
  14. #if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
  15. extern "C" { extern char **environ; }
  16. #endif
  17. BOOST_PROCESS_V2_BEGIN_NAMESPACE
  18. namespace environment
  19. {
  20. using char_type = char;
  21. template<typename Char>
  22. using key_char_traits = std::char_traits<Char>;
  23. template<typename Char>
  24. using value_char_traits = std::char_traits<Char>;
  25. constexpr char_type equality_sign = '=';
  26. constexpr char_type delimiter = ':';
  27. namespace detail
  28. {
  29. BOOST_PROCESS_V2_DECL
  30. basic_cstring_ref<char_type, value_char_traits<char>>
  31. get(basic_cstring_ref<char_type, key_char_traits<char_type>> key, error_code & ec);
  32. BOOST_PROCESS_V2_DECL
  33. void set(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
  34. basic_cstring_ref<char_type, value_char_traits<char_type>> value,
  35. error_code & ec);
  36. BOOST_PROCESS_V2_DECL
  37. void unset(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
  38. error_code & ec);
  39. }
  40. using native_handle_type = const char * const *;
  41. using native_iterator = native_handle_type;
  42. namespace detail
  43. {
  44. BOOST_PROCESS_V2_DECL native_handle_type load_native_handle();
  45. struct native_handle_deleter
  46. {
  47. void operator()(native_handle_type) const {}
  48. };
  49. BOOST_PROCESS_V2_DECL native_iterator next(native_handle_type nh);
  50. BOOST_PROCESS_V2_DECL native_iterator find_end(native_handle_type nh);
  51. inline const char_type * dereference(native_iterator iterator) {return *iterator;}
  52. BOOST_PROCESS_V2_DECL bool is_executable(const filesystem::path & pth, error_code & ec);
  53. }
  54. }
  55. BOOST_PROCESS_V2_END_NAMESPACE
  56. #endif