config.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #elif defined(BOOST_WINDOWS_API)
  50. namespace windows {namespace extensions {}}
  51. namespace api = windows;
  52. inline std::error_code get_last_error() noexcept
  53. {
  54. return std::error_code(::boost::winapi::GetLastError(), std::system_category());
  55. }
  56. #endif
  57. inline void throw_last_error(const std::string & msg)
  58. {
  59. throw process_error(get_last_error(), msg);
  60. }
  61. inline void throw_last_error(const char * msg)
  62. {
  63. throw process_error(get_last_error(), msg);
  64. }
  65. inline void throw_last_error()
  66. {
  67. throw process_error(get_last_error());
  68. }
  69. inline void throw_error(const std::error_code& ec)
  70. {
  71. if (ec)
  72. throw process_error(ec);
  73. }
  74. inline void throw_error(const std::error_code& ec, const char* msg)
  75. {
  76. if (ec)
  77. throw process_error(ec, msg);
  78. }
  79. template<typename Char> constexpr Char null_char();
  80. template<> constexpr char null_char<char> (){return '\0';}
  81. template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';}
  82. template<typename Char> constexpr Char equal_sign();
  83. template<> constexpr char equal_sign<char> () {return '='; }
  84. template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; }
  85. template<typename Char> constexpr Char quote_sign();
  86. template<> constexpr char quote_sign<char> () {return '"'; }
  87. template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; }
  88. template<typename Char> constexpr Char space_sign();
  89. template<> constexpr char space_sign<char> () {return ' '; }
  90. template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; }
  91. }}}
  92. #endif