mitigate.hpp
Go to the documentation of this file.
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//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10/**
11 * \file boost/process/mitigate.hpp
12 *
13 * Helpers to mitigate platform differences.
14 */
15
16#pragma once
17
18#include <boost/asio.hpp>
19#if defined(BOOST_POSIX_API)
20#include <sys/wait.h>
21#endif
22
23namespace boost
24{
25 namespace process
26 {
27
28#if defined(BOOST_WINDOWS_API)
29 using pipe_end = boost::asio::windows::stream_handle;
30#elif defined(BOOST_POSIX_API)
31 using pipe_end = boost::asio::posix::stream_descriptor;
32#endif
33
34 inline const char*
36 {
37#if defined(BOOST_WINDOWS_API)
38 return "NUL";
39#elif defined(BOOST_POSIX_API)
40 return "/dev/zero";
41#endif
42 }
43
44 inline const char*
46 {
47#if defined(BOOST_WINDOWS_API)
48 return "NUL";
49#elif defined(BOOST_POSIX_API)
50 return "/dev/null";
51#endif
52 }
53
54#if defined(BOOST_WINDOWS_API)
55#define BOOST_PROCESS_EXITSTATUS(a) static_cast<int>(a)
56#elif defined(BOOST_POSIX_API)
57#define BOOST_PROCESS_EXITSTATUS WEXITSTATUS
58#endif
59
60#if defined(BOOST_PROCESS_DOXYGEN)
61 /**
62 * Type definition for the end of a pipe.
63 *
64 * On Windows the type is based on boost::asio::windows::stream_handle. On
65 * POSIX it is based on boost::asio::posix::stream_descriptor.
66 *
67 * You can use this type definition for asynchronous I/O with streams of
68 * child processes.
69 */
70 using pipe_end = boost_asio_type;
71
72 /**
73 * Gets the name of the zero device.
74 *
75 * You can use zero_device to initialize a
76 * boost::iostreams::file_descriptor_source to read
77 * null characters from.
78 *
79 * \returns NUL on Windows and /dev/zero on POSIX.
80 */
81 const char* zero_device();
82
83 /**
84 * Gets the name of the null device.
85 *
86 * You can use null_device to initialize a
87 * boost::iostreams::file_descriptor_sink which discards
88 * data written to it.
89 *
90 * \returns NUL on Windows and /dev/null on POSIX.
91 */
92 const char* null_device();
93
94 /**
95 * \def BOOST_PROCESS_EXITSTATUS
96 *
97 * On Windows \c BOOST_PROCESS_EXITSTATUS is a static cast to \c int.
98 * On POSIX it is set to \c WEXITSTATUS.
99 *
100 * You can use \c BOOST_PROCESS_EXITSTATUS for the return value of
101 * boost::process::wait_for_exit to get the exit status of a process.
102 */
103#define BOOST_PROCESS_EXITSTATUS
104#endif
105
106 } // namespace process
107} // namespace boost
const char * zero_device()
Definition mitigate.hpp:35
const char * null_device()
Definition mitigate.hpp:45