config.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include <boost/process/exception.hpp>
  21. #if defined(BOOST_POSIX_API)
  22. #include <errno.h>
  23. #if defined(__GLIBC__)
  24. #include <features.h>
  25. #else
  26. extern char **environ;
  27. #endif
  28. #elif defined(BOOST_WINDOWS_API)
  29. #include <boost/winapi/get_last_error.hpp>
  30. #else
  31. #error "System API not supported by boost.process"
  32. #endif
  33. namespace boost { namespace process { namespace detail
  34. {
  35. #if !defined(BOOST_PROCESS_PIPE_SIZE)
  36. #define BOOST_PROCESS_PIPE_SIZE 1024
  37. #endif
  38. #if defined(BOOST_POSIX_API)
  39. namespace posix {namespace extensions {}}
  40. namespace api = posix;
  41. inline std::error_code get_last_error() noexcept
  42. {
  43. return std::error_code(errno, std::system_category());
  44. }
  45. //copied from linux spec.
  46. #if (_XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
  47. #define BOOST_POSIX_HAS_VFORK 1
  48. #endif
  49. #if (_POSIX_C_SOURCE >= 199309L)
  50. #define BOOST_POSIX_HAS_SIGTIMEDWAIT 1
  51. #endif
  52. #elif defined(BOOST_WINDOWS_API)
  53. namespace windows {namespace extensions {}}
  54. namespace api = windows;
  55. inline std::error_code get_last_error() noexcept
  56. {
  57. return std::error_code(::boost::winapi::GetLastError(), std::system_category());
  58. }
  59. #endif
  60. inline void throw_last_error(const std::string & msg)
  61. {
  62. throw process_error(get_last_error(), msg);
  63. }
  64. inline void throw_last_error(const char * msg)
  65. {
  66. throw process_error(get_last_error(), msg);
  67. }
  68. inline void throw_last_error()
  69. {
  70. throw process_error(get_last_error());
  71. }
  72. inline void throw_error(const std::error_code& ec)
  73. {
  74. if (ec)
  75. throw process_error(ec);
  76. }
  77. inline void throw_error(const std::error_code& ec, const char* msg)
  78. {
  79. if (ec)
  80. throw process_error(ec, msg);
  81. }
  82. template<typename Char> constexpr Char null_char();
  83. template<> constexpr char null_char<char> (){return '\0';}
  84. template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';}
  85. template<typename Char> constexpr Char equal_sign();
  86. template<> constexpr char equal_sign<char> () {return '='; }
  87. template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; }
  88. template<typename Char> constexpr Char quote_sign();
  89. template<> constexpr char quote_sign<char> () {return '"'; }
  90. template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; }
  91. template<typename Char> constexpr Char space_sign();
  92. template<> constexpr char space_sign<char> () {return ' '; }
  93. template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; }
  94. }}}
  95. #endif