environment_posix.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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__)
  15. # include <crt_externs.h>
  16. # if !defined(environ)
  17. # define environ (*_NSGetEnviron())
  18. # endif
  19. #elif defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
  20. extern "C" { extern char **environ; }
  21. #endif
  22. BOOST_PROCESS_V2_BEGIN_NAMESPACE
  23. namespace environment
  24. {
  25. using char_type = char;
  26. template<typename Char>
  27. using key_char_traits = std::char_traits<Char>;
  28. template<typename Char>
  29. using value_char_traits = std::char_traits<Char>;
  30. constexpr char_type equality_sign = '=';
  31. constexpr char_type delimiter = ':';
  32. namespace detail
  33. {
  34. BOOST_PROCESS_V2_DECL
  35. basic_cstring_ref<char_type, value_char_traits<char>>
  36. get(basic_cstring_ref<char_type, key_char_traits<char_type>> key, error_code & ec);
  37. BOOST_PROCESS_V2_DECL
  38. void set(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
  39. basic_cstring_ref<char_type, value_char_traits<char_type>> value,
  40. error_code & ec);
  41. BOOST_PROCESS_V2_DECL
  42. void unset(basic_cstring_ref<char_type, key_char_traits<char_type>> key,
  43. error_code & ec);
  44. }
  45. using native_handle_type = const char * const *;
  46. using native_iterator = native_handle_type;
  47. namespace detail
  48. {
  49. BOOST_PROCESS_V2_DECL native_handle_type load_native_handle();
  50. struct native_handle_deleter
  51. {
  52. void operator()(native_handle_type) const {}
  53. };
  54. BOOST_PROCESS_V2_DECL native_iterator next(native_handle_type nh);
  55. BOOST_PROCESS_V2_DECL native_iterator find_end(native_handle_type nh);
  56. inline const char_type * dereference(native_iterator iterator) {return *iterator;}
  57. BOOST_PROCESS_V2_DECL bool has_x_access(const char * pth);
  58. inline bool is_executable(const filesystem::path & pth, error_code & ec)
  59. {
  60. return filesystem::is_regular_file(pth, ec) && has_x_access(pth.c_str());
  61. }
  62. }
  63. }
  64. BOOST_PROCESS_V2_END_NAMESPACE
  65. #endif