]>
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 | ||
60 | #elif defined(BOOST_WINDOWS_API) | |
61 | namespace windows {namespace extensions {}} | |
62 | namespace api = windows; | |
63 | ||
64 | inline std::error_code get_last_error() noexcept | |
65 | { | |
66 | return std::error_code(::boost::winapi::GetLastError(), std::system_category()); | |
67 | } | |
68 | #endif | |
69 | ||
70 | inline void throw_last_error(const std::string & msg) | |
71 | { | |
72 | throw process_error(get_last_error(), msg); | |
73 | } | |
74 | ||
75 | inline void throw_last_error(const char * msg) | |
76 | { | |
77 | throw process_error(get_last_error(), msg); | |
78 | } | |
79 | ||
80 | inline void throw_last_error() | |
81 | { | |
82 | throw process_error(get_last_error()); | |
83 | } | |
84 | ||
11fdf7f2 TL |
85 | inline void throw_error(const std::error_code& ec) |
86 | { | |
87 | if (ec) | |
88 | throw process_error(ec); | |
89 | } | |
90 | ||
91 | inline void throw_error(const std::error_code& ec, const char* msg) | |
92 | { | |
93 | if (ec) | |
94 | throw process_error(ec, msg); | |
95 | } | |
b32b8144 FG |
96 | |
97 | template<typename Char> constexpr Char null_char(); | |
98 | template<> constexpr char null_char<char> (){return '\0';} | |
99 | template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';} | |
100 | ||
101 | template<typename Char> constexpr Char equal_sign(); | |
102 | template<> constexpr char equal_sign<char> () {return '='; } | |
103 | template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; } | |
104 | ||
105 | template<typename Char> constexpr Char quote_sign(); | |
106 | template<> constexpr char quote_sign<char> () {return '"'; } | |
107 | template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; } | |
108 | ||
109 | template<typename Char> constexpr Char space_sign(); | |
110 | template<> constexpr char space_sign<char> () {return ' '; } | |
111 | template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; } | |
112 | ||
113 | ||
114 | }}} | |
115 | #endif |