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
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)
12 * \file boost/process/config.hpp
14 * Defines various macros.
17 #ifndef BOOST_PROCESS_DETAIL_CONFIG_HPP
18 #define BOOST_PROCESS_DETAIL_CONFIG_HPP
20 #include <boost/config.hpp>
21 #include <system_error>
22 #include <boost/system/api_config.hpp>
24 #include <boost/process/exception.hpp>
26 #if defined(BOOST_POSIX_API)
28 #if defined(__GLIBC__)
31 extern char **environ;
33 #elif defined(BOOST_WINDOWS_API)
34 #include <boost/winapi/get_last_error.hpp>
36 #error "System API not supported by boost.process"
39 namespace boost { namespace process { namespace detail
42 #if !defined(BOOST_PROCESS_PIPE_SIZE)
43 #define BOOST_PROCESS_PIPE_SIZE 1024
46 #if defined(BOOST_POSIX_API)
47 namespace posix {namespace extensions {}}
48 namespace api = posix;
50 inline std::error_code get_last_error() noexcept
52 return std::error_code(errno, std::system_category());
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
60 #if (_POSIX_C_SOURCE >= 199309L)
61 #define BOOST_POSIX_HAS_SIGTIMEDWAIT 1
64 #elif defined(BOOST_WINDOWS_API)
65 namespace windows {namespace extensions {}}
66 namespace api = windows;
68 inline std::error_code get_last_error() noexcept
70 return std::error_code(::boost::winapi::GetLastError(), std::system_category());
74 inline void throw_last_error(const std::string & msg)
76 throw process_error(get_last_error(), msg);
79 inline void throw_last_error(const char * msg)
81 throw process_error(get_last_error(), msg);
84 inline void throw_last_error()
86 throw process_error(get_last_error());
89 inline void throw_error(const std::error_code& ec)
92 throw process_error(ec);
95 inline void throw_error(const std::error_code& ec, const char* msg)
98 throw process_error(ec, msg);
101 template<typename Char> constexpr Char null_char();
102 template<> constexpr char null_char<char> (){return '\0';}
103 template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';}
105 template<typename Char> constexpr Char equal_sign();
106 template<> constexpr char equal_sign<char> () {return '='; }
107 template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; }
109 template<typename Char> constexpr Char quote_sign();
110 template<> constexpr char quote_sign<char> () {return '"'; }
111 template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; }
113 template<typename Char> constexpr Char space_sign();
114 template<> constexpr char space_sign<char> () {return ' '; }
115 template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; }