config.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (c) 2006, 2007 Julio M. Merino Vidal
  2. // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
  3. // Copyright (c) 2009 Boris Schaeling
  4. // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
  5. // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
  6. // Copyright (c) 2016 Klemens D. Morgenstern
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. * \file boost/process/config.hpp
  12. *
  13. * Defines various macros.
  14. */
  15. #ifndef BOOST_PROCESS_DETAIL_CONFIG_HPP
  16. #define BOOST_PROCESS_DETAIL_CONFIG_HPP
  17. #include <boost/config.hpp>
  18. #include <system_error>
  19. #include <boost/system/api_config.hpp>
  20. #if !defined(BOOST_PROCESS_VERSION)
  21. #define BOOST_PROCESS_VERSION 1
  22. #endif
  23. #if BOOST_PROCESS_VERSION == 1
  24. #define BOOST_PROCESS_V1_INLINE inline
  25. #else
  26. #define BOOST_PROCESS_V1_INLINE
  27. #endif
  28. #include <boost/throw_exception.hpp>
  29. #include <boost/process/v1/exception.hpp>
  30. #include <boost/assert/source_location.hpp>
  31. #if defined(BOOST_POSIX_API)
  32. #include <errno.h>
  33. #if defined(__GLIBC__)
  34. #include <features.h>
  35. #else
  36. extern char **environ;
  37. #endif
  38. #elif defined(BOOST_WINDOWS_API)
  39. #include <boost/winapi/get_last_error.hpp>
  40. #else
  41. #error "System API not supported by boost.process"
  42. #endif
  43. namespace boost { namespace process { BOOST_PROCESS_V1_INLINE namespace v1 { namespace detail
  44. {
  45. #if !defined(BOOST_PROCESS_PIPE_SIZE)
  46. #define BOOST_PROCESS_PIPE_SIZE 1024
  47. #endif
  48. #if defined(BOOST_POSIX_API)
  49. namespace posix {namespace extensions {}}
  50. namespace api = posix;
  51. inline std::error_code get_last_error() noexcept
  52. {
  53. return std::error_code(errno, std::system_category());
  54. }
  55. //copied from linux spec.
  56. #if (_XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
  57. #define BOOST_POSIX_HAS_VFORK 1
  58. #endif
  59. #if (_POSIX_C_SOURCE >= 199309L)
  60. #define BOOST_POSIX_HAS_SIGTIMEDWAIT 1
  61. #endif
  62. #elif defined(BOOST_WINDOWS_API)
  63. namespace windows {namespace extensions {}}
  64. namespace api = windows;
  65. inline std::error_code get_last_error() noexcept
  66. {
  67. return std::error_code(::boost::winapi::GetLastError(), std::system_category());
  68. }
  69. #endif
  70. inline void throw_last_error(const std::string & msg, boost::source_location const & loc = boost::source_location())
  71. {
  72. boost::throw_exception(process_error(get_last_error(), msg), loc);
  73. }
  74. inline void throw_last_error(const char * msg, boost::source_location const & loc = boost::source_location())
  75. {
  76. boost::throw_exception(process_error(get_last_error(), msg), loc);
  77. }
  78. inline void throw_last_error(boost::source_location const & loc = boost::source_location())
  79. {
  80. boost::throw_exception(process_error(get_last_error()), loc);
  81. }
  82. inline void throw_error(const std::error_code& ec,
  83. boost::source_location const & loc = boost::source_location())
  84. {
  85. if (ec)
  86. boost::throw_exception(process_error(ec), loc);
  87. }
  88. inline void throw_error(const std::error_code& ec, const char* msg,
  89. boost::source_location const & loc = boost::source_location())
  90. {
  91. if (ec)
  92. boost::throw_exception(process_error(ec, msg), loc);
  93. }
  94. template<typename Char> constexpr Char null_char();
  95. template<> constexpr char null_char<char> (){return '\0';}
  96. template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';}
  97. template<typename Char> constexpr Char equal_sign();
  98. template<> constexpr char equal_sign<char> () {return '='; }
  99. template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; }
  100. template<typename Char> constexpr Char quote_sign();
  101. template<> constexpr char quote_sign<char> () {return '"'; }
  102. template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; }
  103. template<typename Char> constexpr Char space_sign();
  104. template<> constexpr char space_sign<char> () {return ' '; }
  105. template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; }
  106. }
  107. }
  108. }
  109. }
  110. #endif