]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
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 | /** | |
12 | * \file boost/process/config.hpp | |
13 | * | |
14 | * Defines various macros. | |
15 | */ | |
16 | ||
17 | #ifndef BOOST_PROCESS_DETAIL_CONFIG_HPP | |
18 | #define BOOST_PROCESS_DETAIL_CONFIG_HPP | |
19 | ||
20 | #include <boost/config.hpp> | |
21 | #include <system_error> | |
22 | #include <boost/system/api_config.hpp> | |
23 | ||
24 | #include <boost/process/exception.hpp> | |
25 | ||
26 | #if defined(BOOST_POSIX_API) | |
27 | #include <errno.h> | |
28 | #if defined(__GLIBC__) | |
29 | #include <features.h> | |
30 | #else | |
31 | extern char **environ; | |
32 | #endif | |
33 | #elif defined(BOOST_WINDOWS_API) | |
34 | #include <boost/winapi/get_last_error.hpp> | |
35 | #else | |
36 | #error "System API not supported by boost.process" | |
37 | #endif | |
38 | ||
39 | namespace boost { namespace process { namespace detail | |
40 | { | |
41 | ||
42 | #if !defined(BOOST_PROCESS_PIPE_SIZE) | |
43 | #define BOOST_PROCESS_PIPE_SIZE 1024 | |
44 | #endif | |
45 | ||
46 | #if defined(BOOST_POSIX_API) | |
47 | namespace posix {namespace extensions {}} | |
48 | namespace api = posix; | |
49 | ||
50 | inline std::error_code get_last_error() noexcept | |
51 | { | |
52 | return std::error_code(errno, std::system_category()); | |
53 | } | |
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 | ||
92f5a8d4 TL |
60 | #if (_POSIX_C_SOURCE >= 199309L) |
61 | #define BOOST_POSIX_HAS_SIGTIMEDWAIT 1 | |
62 | #endif | |
63 | ||
b32b8144 FG |
64 | #elif defined(BOOST_WINDOWS_API) |
65 | namespace windows {namespace extensions {}} | |
66 | namespace api = windows; | |
67 | ||
68 | inline std::error_code get_last_error() noexcept | |
69 | { | |
70 | return std::error_code(::boost::winapi::GetLastError(), std::system_category()); | |
71 | } | |
72 | #endif | |
73 | ||
74 | inline void throw_last_error(const std::string & msg) | |
75 | { | |
76 | throw process_error(get_last_error(), msg); | |
77 | } | |
78 | ||
79 | inline void throw_last_error(const char * msg) | |
80 | { | |
81 | throw process_error(get_last_error(), msg); | |
82 | } | |
83 | ||
84 | inline void throw_last_error() | |
85 | { | |
86 | throw process_error(get_last_error()); | |
87 | } | |
88 | ||
11fdf7f2 TL |
89 | inline void throw_error(const std::error_code& ec) |
90 | { | |
91 | if (ec) | |
92 | throw process_error(ec); | |
93 | } | |
94 | ||
95 | inline void throw_error(const std::error_code& ec, const char* msg) | |
96 | { | |
97 | if (ec) | |
98 | throw process_error(ec, msg); | |
99 | } | |
b32b8144 FG |
100 | |
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';} | |
104 | ||
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'='; } | |
108 | ||
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'"'; } | |
112 | ||
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' '; } | |
116 | ||
117 | ||
118 | }}} | |
119 | #endif |